Automating administration
Why automate, imperative script versus described state, idempotence, pushing without an agent or pulling with one, and Ansible: inventory, playbook, tasks, modules, variables, handlers and reading a run.
- 25 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- Scenarios
- Understand
A few cards from the deck
Configuration management: what is it?
Show the answer
The practice of bringing and keeping a fleet of machines in the wanted state with tools, rather than typing commands by hand on each one.
Two servers set up by hand end up differing and nobody knows why. A tool applies the same description to all of them, replays it after a failure and makes it reviewable.
Here is a playbook and the output of its first run. It is run again with nothing changed. Which final recap does it show?
```yaml
- hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Create the site directory
ansible.builtin.file: { path: /tmp/ans/www, state: directory }
- name: Write the config
ansible.builtin.copy: { content: "port 80\n", dest: /tmp/ans/www/app.conf }
notify: Restart app
- name: Count the files
ansible.builtin.command: ls /tmp/ans/www
handlers:
- name: Restart app
ansible.builtin.debug: { msg: restarted }
TASK [Create the site directory] ***
changed: [localhost]
TASK [Write the config] ***
changed: [localhost]
TASK [Count the files] ***
changed: [localhost]
RUNNING HANDLER [Restart app] ***
ok: [localhost] => {
"msg": "restarted"
}
PLAY RECAP ***
localhost : ok=4 changed=3 unreachable=0 failed=0`ok=3 changed=1ok=3 changed=0ok=4 changed=3ok=4 changed=1
Show the answer
ok=3 changed=1fileandcopysee the wanted state is already there:ok. Thecommandmodule cannot know what it changes and always reportschanged. Ascopychanged nothing, the handler is not notified and does not run. Theokcounter counts every successful task, changed or not: 3 tasks, 1 of themchanged.Ansible acts over … from the control node, with no … installed on the managed machines: it works in push mode.
Show the answer
Ansible acts over SSH from the control node, with no agent installed on the managed machines: it works in push mode.
In push mode, the administrator triggers the run whenever they choose. In pull mode (Puppet, Chef), each machine periodically queries a central server.
Infrastructure as code: what is it?
Show the answer
Describing servers, their settings and their software in text files, versioned and reviewed like source code.
The files live in Git: you see who changed what, you can roll back and recreate the machine identically instead of repairing it by hand.
A Bash script runs
echo 'port 80' >> app.confto configure each server. After three runs, the file holds threeport 80lines. Which fix applies the declarative approach?- A
lineinfiletask that ensures theport 80line is present - A
shelltask that runs the sameecho, but only once a day on each server - A second script that afterwards removes all the duplicate lines from the file
- A loop that reruns the script until the file stops changing altogether
Show the answer
A
lineinfiletask that ensures theport 80line is presentAppending is an action: each pass repeats it.
lineinfiledescribes a state (this line is present): if it is already there, the task isokand the file stays untouched.- A