4.4 Ansible-Pull

In this lab we’ll have a short glimpse at how ansible-pull works.

Task 1

  • Search docs.ansible.com for information about the ansible-pull command.
  • Look for a way to execute a playbook using ansible-pull
  • Search for an example playbook
Solution Task 1

ansible-pull Ansible-pull GitHub ansible-examples

Task 2

On node1:

  • Install all needed packages to use ansible-pull
  • Use an ansible-pull command 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.yml located at the resource/ansible-pull folder and run it on all hosts in the inventory file hosts
  • Show the content of /etc/motd and verify, that the file was copied using ansible-pull
  • Also verify, that no content of the git repository was copied to the local folder.
Solution Task 2
1
2
3
4
sudo dnf 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...

Task 3

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 ansible the ansible-pull command from Task 2.
  • Now remove the existing /etc/motd file and use the command watch to show the content of /etc/motd every second. We want to observe that our cronjob runs the ansible-pull command again and restore the previously deleted MOTD-file.
Solution Task 3
1
2
3
4
$ 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

Task 4

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 /etc/cron.d/ansible-pull
  • empty the file /etc/motd

Run the playbook.

Solution Task 4
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
$ cat revert_motd.yml
---
- hosts: node1
  become: true
  tasks:
    - name: uninstall ansible
      dnf:
        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

All done?

Last modified November 14, 2022: add http headers (7f665a8)