Linux Labs

Automation: Git and Ansible / Stage 5 of 6

A playbook: tasks, handlers, templates

Not running Starting usually ~20 s
Leave the lesson

Step 5 of 6 · lab · 25 minmedium

An unfinished playbook

The shop status page is to be set up with an Ansible playbook instead of by hand. The playbook is started, but it fails and does not do everything. Finish it so that it sets the machine up by itself and a second run changes nothing.

Situation

The shop servers need a status page. The status-board application is already installed (/usr/local/bin/status-board), but nobody wants to set it up by hand on every server. Timur started an Ansible playbook in ~/status-board and did not get to finish it: ansible-playbook site.yml fails right now.

Task

Finish site.yml so that it brings this machine (localhost from inventory.ini) to the needed state by itself:

  1. The status user is a system user without a login shell (the playbook already has a task for it).
  2. The /var/lib/status data directory: owner and group status, mode 0750.
  3. The /etc/status/status.ini settings come from the templates/status.ini.j2 template with the variables from the playbook's vars:: owner root, group status, mode 0640.
  4. The lab-status service (the unit is files/lab-status.service) is running, enabled at boot and answers: curl http://127.0.0.1:8095/.
  5. Running the playbook again changes nothing: the recap says changed=0.

"Check" runs the playbook by itself. First it removes what the playbook must create: 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 twice, as you. So the playbook must do everything — the check removes whatever you set up by hand.

Do not change the application, the files/lab-status.service file or the variables in vars:.

To run it: cd ~/status-board && ansible-playbook site.yml. Module help — ansible-doc file. 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
  • The playbook creates the status system user and the /var/lib/status directory (status:status, 0750) — not done yet
  • /etc/status/status.ini is built from the templates/status.ini.j2 template (root:status, 0640) — not done yet
  • The lab-status service is running, enabled at boot and answers http://127.0.0.1:8095/ — 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
  • The playbook creates the status system user and the /var/lib/status directory (status:status, 0750) — not done yet
  • /etc/status/status.ini is built from the templates/status.ini.j2 template (root:status, 0640) — not done yet
  • The lab-status service is running, enabled at boot and answers http://127.0.0.1:8095/ — 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
  • The playbook creates the status system user and the /var/lib/status directory (status:status, 0750) — not done yet
  • /etc/status/status.ini is built from the templates/status.ini.j2 template (root:status, 0640) — not done yet
  • The lab-status service is running, enabled at boot and answers http://127.0.0.1:8095/ — not done yet
  • A repeated run changes nothing — changed=0 — not done yet
Loading…