Skip to content



Thank you for taking the time to read through this interactive document; this being the first of 3 parts.

I hope these hands-on, interactive lessons can reduce the startup cost of learning and eventually mastering Ansible.

The Web Terminal

If you want to take advantage of the interactive, hands-on nature of these labs, you'll need to either already have a web terminal connection available or fire one up yourself.

Instructions for that can be found here.

Lesson 01

Here's what I will cover for Lab 1 of this Ansible tutorial series:

  • What is ansible?
  • How to install Ansible on Windows/Linux/MacOS
  • How to prepare a test environment for Ansible using Docker

Let's begin.

What is Ansible?

Ansible is a simple yet powerful tool for configuration management and orchestration of your infrastructure.

It speeds up installing software, configuring servers, and most importantly reduces manual, error-prone methods for managing modern infrastructure components.

It is also a great alternative to Puppet and Chef.

Both are similar tools to Ansible, but in my opinion Ansible is much easier to learn and master.

In a nutshell, Ansible:

  • Is like a higher-level, idempotent version of traditional shell scripts
  • Is much, much easier to rapidly develop and manage, since its automation is (mostly) defined using yaml
  • Lends itself to self-documenting development


Throughout the sections ahead, I'll make reference to the following ansible terms:

  • inventory - This is how ansible is made aware of the machines it is to manage
  • playbooks - This is the ansible version of a bash script
  • tasks - Think of this as you would a neatly commented step in a bash script, only far more superior in structure and clarity
  • variables - Just like bash variables, ansible stores repeatable information in these named constructs
  • facts - Very similar to variables, but think more of these as values that
    are automatically derived from a machine
    or from a little bit of ansible magic

For more information on ansible terms, consult the Ansible Glossary

Let's go over installing Ansible

Installing Ansible

Debian Systems

Installation on Ubuntu 20.04 LTS:

sudo apt-get update
sudo apt-get install -y curl software-properties-common || sudo apt-get install -y python-software-properties
sudo apt-get -y autoremove
sudo apt-get install -y --allow-unauthenticated python-setuptools python-dev libffi-dev libssl-dev git sshpass tree
sudo apt-get -y install python-pip
sudo pip install ansible cryptography

RHEL Systems

Installation on CentOS 8.x, Oracle Enterprise Linux 8.x

rpm -ivh
yum install -y ansible

In the next sections, we'll cover writing and launching ansible playbooks.

My editor of choice is Sublime 3 Text Editor, but we'll be using vi throughout this lab.

Writing ansible playbooks

The fun starts when you learn your way around ansible playbooks!

Let's create some of these, as Follows:

  • Create a folder for your playbook:

    mkdir -p sandbox

  • Create a playbook under this path named hello.yaml

    touch sandbox/hello.yaml

  • Add the playbook definition with a single debug task:

  echo -e """
  - hosts: localhost
    connection: local
      - name: debug | Say Hello!
          msg: |
            Hello from the imported playbook!
  """ >> sandbox/hello.yaml 
  • Run the playbook, specifying your inventory as 'localhost':

    ansible-playbook -i localhost, sandbox/hello.yaml

This concludes lab1.

In lesson-02, we'll be converting a complicated bash shell script into an Ansible Playbook.

Lesson-02 will cover:

  • Playbooks and Tasks
  • Templates and Handlers
  • Variables & Facts
  • Task Blocks