Ansible Masterclass

Duration: 3 days

Infrastructure as code is one of the central mantras of the Devops movement. Adhering to this philosophy means that we facilitate best practices, supporting and encouraging developers to become more involved in defining configuration, thus allowing the operations team to get involved earlier in the development process.

Ansible is a boon to any organisation as it is the simplest way to manage configuration by leveraging native Linux/Unix technologies such as ssh and python, but it is flexible enough to handle complex processes. Linux administrators can use their existing skills to quickly and easily begin using Ansible straight away.

Students should have a basic understanding of linux system concepts. Some optional labs have python development. Solutions are provided for those who are not familiar with Python development. Some basic knowledge of docker is helpfull, but not a requirement.

Please find the course objectives below:

Ansible Introduction

  • Introduce the Ansible project
  • History of Ansible
  • Understand the use-cases for ansible
  • Understand Ansible's idempotent behaviour
  • Ansible nodes (*control machine and managed nodes**)
  • Ansible requirements and installation

Concepts

  • Introduce tasks
  • Understand ansible modules
  • An overview of key modules
  • Understand the role and rational of inventories
  • Defining inventories
  • Defining host groups
  • Using default groups
  • Discuss static and dynamic inventories
  • Running ad-hoc commands with ansible
  • Using inventory patterns
  • Understand how tasks are executed remotely
  • Introduce playbooks
  • Ansible configuration techniques (ansible.cfg, environment variables and cli options)
  • List key configuration parameters
  • Understand variables and facts
  • Understand different variable scopes (global, play and host)
  • Using local facts
  • Define host and group variables
  • Introduce magic variables
  • Introduce jinja2

Ansible Playbooks

  • Overview of yaml (optional)
  • Understand plays and playbooks
  • Defining multiple plays in a playbook
  • Appreciate the anatomy of a play
  • Configure hosts and behaviour for play
  • Define tasks
  • Identity and privilege escalation
  • Using external variable files
  • Prompting for values and passwords
  • Setting facts values
  • Introduce handlers
  • Understand how and when they are invoked
  • Triggering handlers
  • Troubleshooting techniques (check mode, dry mode, step-by-step, diff)

Modules

  • Running commands
  • Managing files and directories (create, delete, etc)
  • Copying files and directories
  • Installing software (packages, pip, bower, gems, …)
  • Managing users, groups and passwords
  • Managing services
  • Managing file contents (lines/blocks/ini files)
  • Templating with jinja2
  • Debugging
  • Managing docker images and containers

Complex playbooks

Managing Secrets with Vaults

  • Appreciate and use vaults
  • Creating and updating vaults
  • Using vaults in playbooks

Include and import

  • Discuss various playbook directory structures
  • Import and include (tasks, playbooks, …)
  • Understand the difference between static and dynamic import/include
  • Discuss various use-cases for import/include
  • Passing variables to import/include

jinja2

  • Explain the jinja2 syntax
  • Understand jinja2's role in ansible
  • Jinja2 expressions (for, if, …)
  • Appreciate jinja2 filters
  • List key filters (built-in jinja2 and ansible specific)
  • Understand lookup
  • Discuss key lookup plugins

Playbook structures

  • Using ansible loops
  • Explain deprecated with_xxx loops
  • Understand the relation between loops, lookup, query and plugins
  • Looping over multiple tasks using include
  • Conditional tasks using when
  • Error handling playbooks
  • Ignoring errors
  • Define what's a failure using failed_when
  • Defining blocks
  • List different run strategies (linear, free and serial)
  • Using batch for rolling updates
  • Appreciate task delegation
  • Use tags to include/exclude tasks

Dynamic inventories

  • Appreciate the need for dynamic inventories
  • list and discuss available dynamic inventories (kubernetes, aws, etc)
  • Developing custom dynamic inventories

Plugins

  • Work with cache plugins
  • Using callback plugin to change the output
  • Using callback plugins to interact with other systems (logback, slack etc)
  • Use different connection types
  • Using windows hosts
  • Executing tasks inside docker containers
  • Using inventory plugins
  • Interacting with kubernetes pods

Ansible Roles & Galaxy

  • Understand the need for roles
  • Understand role structure
  • Using roles with import/include
  • Deprecated use of roles
  • Passing variables
  • Path to roles
  • Introduce Ansible Galaxy
  • Use roles from Galaxy
  • Use the galaxy command line tool
  • Writing roles
  • Defining meta-data (e.g, dependencies)

AWX / Ansible Tower Overview

  • Introduce Ansible Tower
  • Understand the benefits of using Tower
  • Installing Tower
  • Introduce the upstream project AWX
  • Discuss access control
  • Define inventories in Tower/AWX
  • Supply secrets using credentials
  • Define projects (using an SCM)
  • Define job templates
  • Running and monitoring jobs
  • Job scheduling
  • Using roles with requirements.yml
  • Extra: using webhooks to launch a job automatically
For an onsite course please contact us