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.

  1. Concepts
  2. Questions
  3. Sort and link
  4. Scenarios
  5. 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=1
    • ok=3 changed=0
    • ok=4 changed=3
    • ok=4 changed=1
    Show the answer

    ok=3 changed=1

    file and copy see the wanted state is already there: ok. The command module cannot know what it changes and always reports changed. As copy changed nothing, the handler is not notified and does not run. The ok counter counts every successful task, changed or not: 3 tasks, 1 of them changed.

  • 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.conf to configure each server. After three runs, the file holds three port 80 lines. Which fix applies the declarative approach?

    • A lineinfile task that ensures the port 80 line is present
    • A shell task that runs the same echo, 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 lineinfile task that ensures the port 80 line is present

    Appending is an action: each pass repeats it. lineinfile describes a state (this line is present): if it is already there, the task is ok and the file stays untouched.