In this lab we’ll have a short glimpse at how ansible-pull works.
docs.ansible.comfor information about the ansible-pull command.
- Look for a way to execute a playbook using ansible-pull
- Search for a example playbook
- Install all needed packages to use ansible-pull
- Use an
ansible-pullcommand that uses the resources in the folder
resources/ansible-pull/of our github repository located at
https://github.com/puzzle/ansible-techlab. This command should do the following:
- Apply the playbook
local.ymllocated at the
resource/ansible-pullfolder and run it on all hosts in the inventory file
- Show the content of
/etc/motdand verify, that the file was copied using ansible-pull
- Also verify, that no content of the git repository was copied to the local folder.
Note the following:
- If no playbook is specified, ansible-pull looks for a playbook
- The location of files given as paratmeters to the ansibel-pull command ar always relative to the top level of the git repository.
- All information to run the ansible-pull command is taken from the git repository (playbook, inventory, MOTD-file to be copied). No local configuration is used!
It’s a best practice to use cronjobs to trigger
ansible-pull run at a regular basis. Do the following on node1:
- Create a cronjob
/etc/cron.d/ansible-pull. This cronjob should run every minute as user root the ansible-pull commant from Task 2.
- Now remove the existing
/etc/motdfile and use the command
watchto show the content of
/etc/motdevery second. We want to observe that our cronjob runs the
ansible-pullcommand again and restore the previously deleted MOTD-file
This task has nothing to do with
ansible-pull, we just clean up the ansible-pull configurations. Create a playbook
revert_motd.yml that runs on node1. It should:
- uninstall ansible
- remove the cronjob
- empty the file
Run the playbook.
$ sudo yum install -y ansible $ /usr/bin/ansible-pull -U https://github.com/puzzle/ansible-techlab -i resources/ansible-pull/hosts resources/ansible-pull/local.yml $ cat /etc/motd $ ll #no file here...
$ sudo vim /etc/cron.d/ansible-pull #create the file with the content -> $ cat /etc/cron.d/ansible-pull * * * * * ansible /usr/bin/ansible-pull -U https://github.com/puzzle/ansible-techlab -i resources/ansible-pull/hosts resources/ansible-pull/local.yml $ sudo rm -f /etc/motd; watch cat /etc/motd
$ cat revert_motd.yml --- - hosts: node1 become: yes tasks: - name: uninstall ansible yum: name: ansible state: absent - name: ensure cronjob not present file: path: /etc/cron.d/ansible-pull state: absent - name: ensure MOTD file empty copy: content: "" dest: /etc/motd $ ansible-playbook revert_motd.yml