[ norboten ]
ansible · lab ansible-01

The Playbook That Changes Everything, Every Time

· about 35 minutes · runs on ubuntu-26.04-devops · unrated

An unrated lab. It runs on your machine with no account and no network, and everything about it — the faults, the checks, the hints and the reference solution — is in the repository. An attempt on it is recorded on your profile and never moves a rating: only rated labs do. Rated and unrated labs.

The briefing

/srv/ansible holds the playbook that configures this machine as an application host: an app account, the application in /opt/app, its configuration in /etc/app/app.conf, the app systemd service, and IP forwarding for the containers it will run.

cd /srv/ansible && sudo ansible-playbook site.yml

Every run reports most tasks as changed, restarts the application whether or not anything changed, and grows a file a little. --check is useless: it skips half the tasks. And the application listens on 8080 although the inventory for the app group says 8081.

What is expected, and graded:

  1. The application answers on the port the inventory gives it, 8081, and still does after a reboot.
  2. IP forwarding is on, configured in exactly one line, and stays on after a reboot.
  3. On this machine, ansible-playbook site.yml --check runs every task — none skipped — and finds nothing to change.

The grader runs the playbook in check mode only; it never applies it for you. You have root through sudo. There is no internet access, and none is needed.

What is graded

The machine is checked, rebooted, and checked again. A check passes only if it passes both times.

CheckObjective
01_app_on_the_inventory_portKnow where a variable's value comes from, and set it where it belongs
02_forwarding_configured_onceDescribe state with modules, so a playbook converges and a second run changes nothing
03_check_mode_finds_nothing_to_doDescribe state with modules, so a playbook converges and a second run changes nothing

Start it

  1. 2Labs
  2. ansible-01select this one
  3. udownload it
  4. sstart the machine

Reading

Where the lab's hints send you, level by level, as you ask for them (h, then l opens a journal section in the TUI).

Theory for this lab

4 questions on the same topic, in the lab's Theory tab. They never affect the lab's grade. Three of them, to answer here:

Question 1

A task is `ansible.builtin.shell: echo "x=1" >> /etc/app.conf`. What happens on the third run?

Question 2

A variable is set in inventory `group_vars/app.yml`, in the play's `vars:`, and with `-e` on the command line. Which value do tasks see, and which would they see without `-e`?

Question 3

What does `skipped=4` in the recap of `ansible-playbook site.yml --check` usually mean when no task has a `when:` condition?