Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

DI 2.14: Automating changes with an Ansible playbook

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

60 minutes

Forty laptops, one afternoon

A school gets forty new laptops. Each one needs the same program and the same welcome file.

Doing it by hand takes a full day, and someone always forgets a step. A technician writes the steps once in a file. The computer does them forty times, the same way each time.

Key words

WordWhat it means
Automationgetting a computer to do a repeated job without a person
Scripta short program that does a job for you
Ansiblea tool that sets up machines from a file that describes how they should be
Playbookthe Ansible file that lists the jobs to do
Taskone job in a playbook, such as installing a package
Modulea ready-made Ansible tool for one kind of job
Idempotentsafe to run again: a second run changes nothing that is already right
Templatea file with gaps that a variable fills in
Variablea name that holds a value, which you can change in one place
Packagea program bundled so that a system can install it

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can use a playbook to automate changes and explain why running it twice is safe.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Say what you want, not how

A shell script says how: do this, then that. An Ansible playbook says what: this package is installed, this file looks like this.

Ansible checks each task. If the machine is already right, it does nothing. If not, it fixes it. So a playbook is idempotent: you can run it twice and the second run changes nothing.

Three tasks and their modules

JobModuleWhat it says
Install a programansible.builtin.aptThe package tree must be present
Make a folderansible.builtin.fileThe folder must exist, with these rights
Make a file from a templateansible.builtin.templateThe file must look like the template, with the variable filled in

The cells students fill in are left blank in this preview.

Run a real playbook

The lab has a folder called ansible-lab. It holds a playbook site.yml with one task that only prints a message.

Press Start the lab. Run the playbook as it is.

Run the playbook as it is

Command
cd ~/ansible-lab && ansible-playbook site.yml

A command for the lesson’s lab terminal. It is shown here and not run.

Read the recap line

Note

The last line is the recap. It counts ok, changed and failed tasks. This run says changed=0 because the only task prints a message.

The lesson goes on

11 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.