mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-02 04:04:23 -07:00
Add some comments to ansible-pull and the example playbook
This commit is contained in:
parent
e54eeb7629
commit
a33320d03d
2 changed files with 41 additions and 2 deletions
|
@ -1,5 +1,15 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# ansible-pull is a script that runs ansible in local mode
|
||||||
|
# after checking out a playbooks directory from git. There is an
|
||||||
|
# example playbook to bootstrap this script in the examples/ dir which
|
||||||
|
# installs ansible and sets it up to run on cron.
|
||||||
|
#
|
||||||
|
# usage:
|
||||||
|
# ansible-pull -d /var/ansible/local -U http://wherever/content.git -C production
|
||||||
|
#
|
||||||
|
# the git repo must contain a playbook named 'local.yml'
|
||||||
|
|
||||||
# (c) 2012, Stephen Fromm <sfromm@gmail.com>
|
# (c) 2012, Stephen Fromm <sfromm@gmail.com>
|
||||||
#
|
#
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
# Ansible is free software: you can redistribute it and/or modify
|
||||||
|
@ -47,6 +57,7 @@ def main(args):
|
||||||
|
|
||||||
git_opts = "repo=%s dest=%s version=%s" % (options.url, options.dest, options.checkout)
|
git_opts = "repo=%s dest=%s version=%s" % (options.url, options.dest, options.checkout)
|
||||||
cmd = 'ansible all -c local -m git -a "%s"' % git_opts
|
cmd = 'ansible all -c local -m git -a "%s"' % git_opts
|
||||||
|
print "cmd=%s" % cmd
|
||||||
rc = _run(cmd)
|
rc = _run(cmd)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
return rc
|
return rc
|
||||||
|
|
|
@ -1,22 +1,50 @@
|
||||||
|
# ansibple-pull setup
|
||||||
|
#
|
||||||
|
# on remote hosts, set up ansible to run periodically using the latest code
|
||||||
|
# from a particular checkout, in pull based fashion, inverting Ansible's
|
||||||
|
# usual push-based operating mode.
|
||||||
|
#
|
||||||
|
# This particular pull based mode is ideal for:
|
||||||
|
#
|
||||||
|
# (A) massive scale out
|
||||||
|
# (B) continual system remediation
|
||||||
|
#
|
||||||
|
# DO NOT RUN THIS AGAINST YOUR HOSTS WITHOUT CHANGING THE repo_url
|
||||||
|
|
||||||
|
|
||||||
|
# FIXME: change the host group for safety
|
||||||
|
|
||||||
---
|
---
|
||||||
- hosts: all
|
- hosts: all
|
||||||
user: root
|
user: root
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
|
|
||||||
# schdule is fed directly to cron
|
# schdule is fed directly to cron
|
||||||
schedule: '*/15 * * * *'
|
schedule: '*/15 * * * *'
|
||||||
|
|
||||||
# User to run ansible-pull as from cron
|
# User to run ansible-pull as from cron
|
||||||
cron_user: root
|
cron_user: root
|
||||||
|
|
||||||
# Directory to where repository will be cloned
|
# Directory to where repository will be cloned
|
||||||
workdir: /var/lib/ansible/local
|
workdir: /var/lib/ansible/local
|
||||||
# Repository to check out
|
|
||||||
repo_url: git://github.com/sfromm/ansible-playbooks.git
|
# Repository to check out -- YOU WANT TO CHANGE THIS
|
||||||
|
#repo_url: git://github.com/sfromm/ansible-playbooks.git
|
||||||
|
repo_url: git://github.com/mdehaan/ansible-examples.git
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
- name: Install ansible
|
- name: Install ansible
|
||||||
action: yum pkg=ansible state=installed
|
action: yum pkg=ansible state=installed
|
||||||
|
|
||||||
- name: Create local directory to work from
|
- name: Create local directory to work from
|
||||||
action: file path=$workdir state=directory owner=root group=root mode=0751
|
action: file path=$workdir state=directory owner=root group=root mode=0751
|
||||||
|
|
||||||
- name: Copy ansible inventory file to client
|
- name: Copy ansible inventory file to client
|
||||||
action: copy src=/etc/ansible/hosts dest=/etc/ansible/hosts
|
action: copy src=/etc/ansible/hosts dest=/etc/ansible/hosts
|
||||||
owner=root group=root mode=0644
|
owner=root group=root mode=0644
|
||||||
|
|
||||||
- name: Create crontab entry to clone/pull git repository
|
- name: Create crontab entry to clone/pull git repository
|
||||||
action: template src=templates/ansible-pull.j2 dest=/etc/cron.d/ansible-pull owner=root group=root mode=0644
|
action: template src=templates/ansible-pull.j2 dest=/etc/cron.d/ansible-pull owner=root group=root mode=0644
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue