Automation 101 with Ansible

Kevin Howell

2020-06-13 - Southeast Linux Fest

Who Am I? (or

Red Hat Certified Architect

Principal Software Engineer

Subscription Management

In This Talk

What is automation, in the general sense?

What kinds of things can you automate?

Ansible Lingo

Be Inspired!

What Is Automation?

"The act or process of converting the controlling of a machine or device to a more automatic system, such as computer or electronic controls." - Wiktionary

What Is Automation?

"Moving pieces, or all, of a process to a machine" - me

Programming == Automation?

Is computer programming automation?

Programming == Automation?


Programming == Automation?

... No!

Programming == Automation?

Well, it depends...

Programming is one kind of automation

Not all programming is automation and not all automation is programming

Game Programming

Not automation*. But a lot of fun!

Trivia: Jerry Lawson is credited with inventing the first cartridge based gaming system in 1976!

Evan-Amos / CC BY-SA (
By Source (WP:NFCC#4), Fair use, Link

The Assembly Line

Automation Predates the Term

From 1790, the automated mill:

What Can Be Automated?

Any Repeatable Process...

Modern Automation

Computers are super accessible in modern society.

Save the Trees!

Ashraful Islam Shimul / CC BY-SA (

Ansible Lingo

Learn How To Speak Ansible

Ansible Lingo - Playbook

A set of tasks to be performed against a set of systems.

Example filenames:

  • provision_vm.yml
  • enter_outage.yml

Ansible Lingo - Task

Something for a system to do.

Examples task names:

  • Configure httpd
  • Generate the TPS report

Ansible Lingo - Inventory

Record of systems for Ansible to orchestrate. The most basic form is an ini-file. Default path is /etc/ansible/hosts




Ansible documentation prefers "nodes" to "systems"... Inventory can contain abstract resources such as containers or network equipment.

Inventories include:

  • connection information (SSH or WinRM)
  • arbitrary data for a given system

Ansible Inventory - With Variables

[databases] postgresql_version=12.3 postgresql_version=10.13

[webservers] ansible_user=admin

Ansible Lingo - Module

Re-usage piece of Ansible logic

Has a set of arguments

A module with a set of arguments forms a task

Most modules are idempotent

Ansible Lingo - YAML

Ansible uses YAML (Yet Another Markup Language) to define tasks and playbooks.

I think of YAML as an alternative syntax to JSON

Strings, Numbers, Arrays, Objects.


# task list
- walk the dog
- mow the lawn

# talk description - nested objects
    id: 101
    title: "Automation 101 w/ Ansible"
      - ansible
      - automation

Ansible Module - Template


- name: Configure hosts files
    src: /home/user/ansible/templates/hosts.j2
    dest: /etc/hosts

/home/user/ansible/templates/hosts.j2:   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6   {{ development_hostname }}

development_hostname could be, for example:

Ansible Module - command


- name: Backup my stuff
  command: /opt/

Ansible - Example Playbook


- hosts: databases
    - name: Configure postgres database
        src: /home/user/ansible/templates/pg_hba.j2
        dest: /var/lib/pgsql/pg_hba.conf
    - name: Upgrade postgres via pg_upgrade
      command: pg_upgrade -b /dbbackup -B /var/lib/pgsql/data -d /dbconfig -D /var/lib/pgsql

If in a file named update_postgres.yml, can be invoked as ansible-playbook update_postgres.yml

Things I've done with Ansible

Ansible - Some Random Ideas

nightly reboot of flaky service, followed by sanity checks

interact with APIs

full system configuration - bare metal to running machine

Ansible - Other Things You Can Do With Ansible

Manage public cloud provider resources (e.g. AWS, Azure, Google)

Manage databases and users

Sync directories/files via rsync, git, http, ftp

Interact with alerting/monitoring systems

Send messages to IRC, Slack, etc.

Ansible - But Wait There's More

Manage users, groups, firewall, etc.

Manage Windows machines

and more...

For more details see

Ansible - Ideas for Further Study

Ansible Vault

Ansible Privilege Escalation

Ansible Jinja2 Filters

Ansible Roles

Dynamic Inventory

Ansible Galaxy

Ansible - Resources - See how others automate with Ansible, reuse existing work

Consider Red Hat training for Ansible

Consider Ansible Automation Platform

  • includes Ansible Tower - Web UI w/ Enterprise Features

Ansible - More Resources - DIY cloud via Ansible - my personal Ansible automation - curated list of Ansible resources (unmaintained)