Automation: Git and Ansible / Final lab
A site on node2, by a playbook from node1
Situation
The team's status page is moving to node2. A colleague put together an Ansible project ~/deploy on
node1: the site.yml playbook sets up the nginx site status on node2 on port 8080 — the site config and
the page from the templates in templates/, with the release taken from the release variable — and
reloads nginx with a handler. Before leaving, the colleague ran the playbook: ansible-playbook site.yml
finished without errors, yet there is no page on node2. The playbook is going to run every day, so a second
run must change nothing.
node1 is your terminal: Ansible runs here, as student, from the ~/deploy directory. student logs in to
node2 with a key: ssh node2 'command' or ssh node2, and exit to come back. sudo works without a
password on both machines.
Task
ansible-playbook site.ymlon node1 configures node2, and the playbook's tasks run on node2.- From node1
curl http://node2:8080/gets the page from the template — with the release from thereleasevariable. - When the site config on node2 has drifted from the template, a run restores it and nginx reloads the config; a run without changes leaves nginx alone.
- A second run succeeds and changes nothing (
changed=0), andansible-playbook site.yml --check --difffinds no differences.
Constraints
- Fix the
~/deployproject: the playbook configures node2. A manual edit on node2 is brought back to the template by the next run, so the check does not count it. - The check runs the playbook itself as student: a normal run (twice if the first one changed something),
a run with
--check --diff, and then it appends a line to/etc/nginx/sites-available/statuson node2 and runs it once more — the playbook has to bring the file back to the template, and nginx has to reload the config.
There is no internet in the lab — only the network between node1 and node2. Everything needed is installed on both machines. After every change run the playbook and look beyond the exit code: at the warnings and the
PLAY RECAP.
Lab goals
0 of 5-
The site.yml playbook targets node2, and its tasks run on node2 — not checked yet
-
From node1 http://node2:8080/ serves the page from the template, with the release from the release variable — not checked yet
-
When the site config on node2 has drifted from the template, a run restores it and nginx reloads the config; a run without changes leaves nginx alone — not checked yet
-
Running ansible-playbook site.yml again succeeds and changes nothing (changed=0) — not checked yet
-
ansible-playbook site.yml --check --diff finds no differences on node2 — not checked yet