ansible playbook

Ansible tasks can be grouped together to be run as a single batch job by creating a playbook containing all of the tasks we want. Not all of these will be specific to the XU-4 Cloudshell, but we'll take a look at those anyway.

We'll create our new playbook as a file called ansible-playbook.yml and add the following lines to it:

- hosts: odroid_headless
  remote_user: root

    - include: ./ubuntu-update.yml
      # [watch this space]
    - include: ./reboot.yml

This is just a skeleton playbook that contains no tasks at all. We'll split the tasks out into separate files to make it easier to maintain, and also to allow reuse of these tasks for other platforms (such as other XU-4 configurations and other non-Odroid platforms).

The Ansible playbook format is well documented elsewhere, but here's an overview of what we have in ours:

  1. The host group name from our inventory that we want to apply this playbook to.
  2. The remote user (root) to perform tasks as.
  3. A task list that consists only of a couple of statements to include other files that we'll introduce below.

included files

We've specified two other files containing playbook fragments. One to perform Ubuntu updates at the start (followed by a placeholder comment where we'll add additional files later), and one to perform at the end that will optionally reboot the node at the end. Here are those files:

First, we'll use the apt module for Ansible to forcibly update the package cache (equivalent of an apt-get update) and then upgrade the distribution accordingly (the equivalent of an apt-get dist-upgrade):

# upgrade ubuntu system
      - name: Update package cache and packages
            upgrade: dist
            update_cache: yes

And secondly, we optionally reboot the system if the upgrade mandates it. This will generally be the case for systems that are freshly provisioned or that have kernel/bootloader updates, but not in other cases. We do this by having Ansible check for the existence of /var/run/reboot-required:

    - name: Check if reboot is required
      register: file
      stat: path=/var/run/reboot-required

    - name: Reboot host
      command: /sbin/reboot
      when: file.stat.exists == true

Go Back

Twitter: @IncompleteIO