Linux Labs

Automation: Git and Ansible / Stage 7 of 8

Roles, variables and secrets

Not running Starting usually ~20 s
Leave the lesson

Step 5 of 6 · lab · 30 minmedium

The role does not apply

The status page playbook was turned into a role so that every shop can use it. On this machine the role fails, and when it passes it shows another shop. Fix the role without touching the values in site.yml.

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:

  1. ansible-playbook site.yml runs without errors.
  2. The /etc/status/status.ini settings are built from the status.ini.j2 role template with the title and port from site.yml: owner root, group status, mode 0640.
  3. The lab-status service is running, enabled at boot and answers: curl http://127.0.0.1:8096/ gives the title «Магазин «Север»: статус витрины».
  4. A run that has changed the settings restarts the service, and a run without changes leaves it alone.
  5. 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 · on your own

No commands are given in this lab: type them in the terminal yourself. Goals are checked on the machine after every command.

Goals

0 of 5
  • ansible-playbook site.yml runs without errors on a machine without the status page — not done yet
  • /etc/status/status.ini is built from the role template with the values from site.yml (root:status, 0640) — not done 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 done yet
  • The service restarts when a run has changed the settings, and only then — not done yet
  • A repeated run changes nothing — changed=0 — not done yet
Ctrl+Enter
Starts the machine node1 · Ubuntu 24.04

The machine is starting

Hints

0 of 3

Lab goals

0 of 5
  • ansible-playbook site.yml runs without errors on a machine without the status page — not done yet
  • /etc/status/status.ini is built from the role template with the values from site.yml (root:status, 0640) — not done 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 done yet
  • The service restarts when a run has changed the settings, and only then — not done yet
  • A repeated run changes nothing — changed=0 — not done yet
node1 Ubuntu 24.04

Lab goals

0 of 5
  • ansible-playbook site.yml runs without errors on a machine without the status page — not done yet
  • /etc/status/status.ini is built from the role template with the values from site.yml (root:status, 0640) — not done 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 done yet
  • The service restarts when a run has changed the settings, and only then — not done yet
  • A repeated run changes nothing — changed=0 — not done yet
Loading…