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
| Word | What it means |
|---|---|
| Automation | getting a computer to do a repeated job without a person |
| Script | a short program that does a job for you |
| Ansible | a tool that sets up machines from a file that describes how they should be |
| Playbook | the Ansible file that lists the jobs to do |
| Task | one job in a playbook, such as installing a package |
| Module | a ready-made Ansible tool for one kind of job |
| Idempotent | safe to run again: a second run changes nothing that is already right |
| Template | a file with gaps that a variable fills in |
| Variable | a name that holds a value, which you can change in one place |
| Package | a 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 questionsYour 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
| Job | Module | What it says |
|---|---|---|
| Install a program | ansible.builtin.apt | The package tree must be present |
| Make a folder | ansible.builtin.file | The folder must exist, with these rights |
| Make a file from a template | ansible.builtin.template | The 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
cd ~/ansible-lab && ansible-playbook site.ymlA 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.