Ansible Intro

Automation is everywhere. I decided to take a quick look into Ansible

Ansible is the simplest way to automate apps and IT infrastructure using SSH, with no agents to install on remote systems.

Here is Intro to Ansible.

Ansible – Open Source IT Automation Platform


  • using SSH and does not require an agent
  • written in Python
  • push-based architecture

Ansible Components

  • Ansible Core – free open source, no support, help is in the community
  • Ansible Engine – the same code as Core, but supported by Red Hat (better for enterprise)
  • Ansible Tower – GUI front end for Ansible Core – licensed
  • Ansible AWX – Open-source version of Ansible Tower

How to install Ansible (CentOS)

$ sudo yum install epel-release
$ sudo yum install ansible
#check version
$ ansible –version

Ansible Terminology

  • Control node – Ansible and Python installed
  • Management nodes – the network devices or servers to manage with Ansible
  • Inventory – the file defines the hosts and groups of hosts, commands, modules, and tasks in a playbook
    • static or dynamic file
    • INI or YAML file
    • default hosts file: /etc/ansible/hosts
  • Modules – the code that Ansible executes (python files)
  • Tasks – specific actions to perform within a Playbook
  • Variables – something different about a specific host
  • Playbooks – collection tasks written in YAML
    • ansible.cfg – config file defines all custom options
    • /etc/ansible/ansible.cfg

YAML format

  • starts with “- – -” and ends with “…”
  • task start with “- name: “
  • use spaces

Hosts file

Variables could be configured as global and common for all devices right inside the hosts file (not recommended) or individually in the host_var or in the group_var.
The host can be in multiple groups.


Playbook 1 to backup all config. 

to run the playbook:

ansible-playbook playbook1.yml

Available options:

  • -u username
  • -k password
  • –limit – limit playbook to run on one device name
  • -i – specify the host file

Ansible makes changes only if there is a difference with existing output.

To change the default setting to display line numbers in vi/vim:

vi ~/.vimrc
# then add the following line to the file:
set number

Gather facts

Facts – information that we derive from speaking with the remote system. Ansible uses the setup module to discover this information automatically.

It could be very time-consuming.

Run playbook with conditions

– – –
 – name: first playbook with when
   gather_facts: false
   hosts: all
    – name: backup
      backup: yes
      register: backup_ios_location
      when: ansible_network_os == ‘aci’


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *