Ansible For Configuration Management

Ansible For Configuration Management

Configuration management (CM) is a system engineering process for establishing and maintaining consistency of a product’s performance, functional, and physical attributes with its requirements, design, and operational information throughout its life.

Configuration Management represents a cornerstone of DevOps and is something that Ansible manages very well

How Ansible Simplifies DevOps Implementations –

Ansible is a relatively new player in the software Configuration Management space. Its initial entry into
space was as an open source software creation managed by the team at Ansible in 2012. The name
Ansible is derived from the 1980s novel Ender’s Game and was selected by Ansible creator, Michael
DeHaan. The main effort behind the solution was to provide a simple-to-use and human-readable
implementation of a Configuration Management solution.

Following were the key principles of Ansible –

  • Minimal development required: Ansible is lightweight and easy to manage.
  • Consistent in execution: Ansible aims to provide a consistent set of rules and expectations in its core implementation.
  • Secure: The Ansible platform was developed using SSH as its recommended protocol, which provides a secure transport method for remote execution of Configuration Management code.
  • Scalable: It can scale from one server to 1000 servers with ease
  • Highly reliable in nature: Providing a consistent execution model is the aim of Ansible—a very reliable execution platform with minimal bugs.
  • Easy to learn: Ansible is easy to learn as compared with other tools present in the market.

Basic Principles of Configuration Management

  • Automate where automation is possible.
  • Provide traceability within the enterprise.
  • Provide developers, QA, operations, and management with a reproducible infrastructure that is managed through software-development best practices
  • Develop a strategy for how new hardware will be provisioned and configured (in an automated way)
  • Manage hardware configurations effectively and with strategy
  • Develop mechanisms that provide a self-service model for deploying infrastructure changes

Installing Ansible:

OS – Ubuntu – 16.04

1. Using package Manager apt

$sudo apt-get install software-properties-common -y
$sudo apt-add-repository ppa:ansible/ansible
$sudo apt-get update
$sudo apt-get install ansible -y

2. Using python pip

$sudo easy_install pip
$sudo pip install ansible

Check Ansible version –

ansible --version
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/ansible/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

Setting up authentication between the control server and hosts

Control Server – Where we have installed ansible using one of the above methods

Hosts – Client Machines where we need to push configurations.

Generate Key Pair using ssh-keygen command

ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ansible/.ssh/id_rsa):
Created directory '/home/ansible/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ansible/.ssh/id_rsa.
Your public key has been saved in /home/ansible/.ssh/
The key fingerprint is:
SHA256:SalFEUPS+cYMxGNwXTasnsNgaa67MPQcxFhmh+Gcp+o [email protected]
The key's randomart image is:
+---[RSA 2048]----+
| BOX= o+ |
| O.*Bo.... |
| . *.=B . |
| . *=.* |
| . ++S= . |
| . + .. = |
| + o. . |
| . o. |
| E oo |

Adding the Public key to hosts machine – 

ssh [email protected] mkdir -p .ssh
cat .ssh/ | ssh [email protected] 'cat >> .ssh/authorized_keys

Ad hoc Linux echo command against a local system

$ ansible localhost -m shell -a 'echo helloDevOpsWorld'

localhost | SUCCESS | rc=0 >>

The Ansible Architecture

Ansible playbooks – Playbooks are essentially sets of instructions (plays) that you send to run on a single target or groups of targets (hosts).

Ansible playbooks are written in Yet Another Markup Language (YAML).

Playbook example –


- hosts: all
    - shell: echo "hello world"

In above playbook we are using shell module to print hello world.


Remote execution using above playbook – 


One Reply to “Ansible For Configuration Management”

Leave a Reply

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