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 1 of 6 · on a machine · 5 min

Running it again changes everything again

What you will learn

  • Read a playbook and the PLAY RECAP report and replace shell tasks with the file, copy, service modules so that a run gives changed=0.
  • Restart a service with a handler (notify and handlers) only in the run where its config changed.
  • Build a file from a template with a variable and see what a run would change with --check --diff.

The shop site on app1 is deployed by a colleague's playbook — the ~/ansible-lab/site.yml file with steps for Ansible. It has already been applied, and the site on port 8080 works. But every run breaks visitors' connections. Run the playbook once more and see what it does.

Exercise · look

Run the playbook once more

In ~/ansible-lab look at the site.yml playbook, run it once more and see when nginx was started.

First, predict

The playbook is already applied and the site works. How many tasks will the run mark as changed?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

The playbook is already applied, yet the repeated run marked all three tasks changed again. Why?

  • A module with nothing to change answers ok: the second ansible web -m copy … in the previous lesson answered SUCCESS with "changed": false.

  • The files are the same: the run writes them again with the same content. cat /srv/shop/index.html before and after the run shows the same thing.

  • A restart does not touch the files, and it is only the third task; the two file tasks say changed too.

All three tasks are shell, and shell answers changed on every run.

Ubuntu 24.04
Loading…