Automation: Git and Ansible / Stage 7 of 8 · step 5 of 6
The role does not apply
Situation
Every shop in the chain now needs the status page, and Timur did not want to copy the playbook. He moved the tasks of
the «Юг» (South) shop playbook into the status_board role and left each shop a short site.yml: its own title and
port in vars: and a roles: line. This machine is the «Север» (North) shop, the project is in ~/status-board.
ansible-playbook site.yml fails here.
Task
Fix the roles/status_board role so that site.yml brings this machine (localhost from inventory.ini) to the
needed state by itself:
ansible-playbook site.ymlruns without errors.- The
/etc/status/status.inisettings are built from thestatus.ini.j2role template with the title and port fromsite.yml: owner root, groupstatus, mode0640. - The
lab-statusservice is running, enabled at boot and answers:curl http://127.0.0.1:8096/gives the title «Магазин «Север»: статус витрины». - A run that has changed the settings restarts the service, and a run without changes leaves it alone.
- Running the playbook again changes nothing: the result is
changed=0.
"Check" runs the playbook itself. First it removes what the role does: the lab-status service with its unit,
/etc/status, /var/lib/status and the status user. Then it runs ansible-playbook site.yml from
~/status-board as you twice, edits the title line in /etc/status/status.ini by hand and runs it a third time —
the service must restart. The last run is --check --diff on a copy of the project where site.yml has a different
title and port: the settings must get them. So the role must do everything — whatever you set up by hand, the check
removes.
Do not change the values in site.yml, the application or the role's lab-status.service unit file.
Run:
cd ~/status-board && ansible-playbook site.yml. What the role holds:find roles -type f. There is no internet on the machine.
Lab goals
0 of 5-
ansible-playbook site.yml runs without errors on a machine without the status page — not checked yet
-
/etc/status/status.ini is built from the role template with the values from site.yml (root:status, 0640) — not checked yet
-
The lab-status service is running, enabled at boot and answers http://127.0.0.1:8096/ with the title from site.yml — not checked yet
-
The service restarts when a run has changed the settings, and only then — not checked yet
-
A repeated run changes nothing — changed=0 — not checked yet