Ansible - In a Nutshell

Ansible is an open-source automation platform. It is simple to set up, efficient and powerful. Key use cases supported are as follows.

  • Application Deployment
  • Configuration Management
  • Automation of Tasks
  • IT orchestration

It is available for free and open-source. The Enterprise version is available in the name of “Ansible Tower”. The benefits of using Ansible are as follows.

  1. Agentless – Not a Master-Client model & No need to install Agent on the client-side
  2. Lightweight and faster to deploy through SSH for operation on the network
  3. The language used is ‘Python”, which is inbuilt into Unix/Linux deployments
  4. YAML syntax for file configuration
  5. Larger Community for support

See the below link for Ansible Terminologies

Install Ansible using apt -get (or) yum commands:-

  • apt -get install ansible
  • yum install ansible

Inventory File & Parameters Management:- 

  • Systems in the infrastructure are managed through the hosts file, the default path is /etc/ansible/hosts
  • Enable password-less SSH Authentication between Ansible server and client host systems

For example, if you have database & web servers you can indicate it in the host’s file as follows

  • [database-servers]
  • ansible_connection=ssh ansible_user=test1
  • ansible_connection=ssh ansible_user=test2
  • [webservers]
  • ansible_connection=ssh ansible_user=testws1
  • ansible_connection=ssh ansible_user=testws2

ansbile_connection: connection type to the host

ansible_user: Default ssh user name to use

For more information on ansible parameters, see the below link

How Ansible works:-


Ansible Configuration Files:-

  • The Default Ansible configuration file is located at “/etc/ansible/ansible.cfg”
  • Flexibility to use multiple configuration files depending upon the environment
[root@<server_name> ~]# vi /etc/ansible/ansible.cfg
# config file for ansible —
# ===============================================
# nearly all parameters can be overridden in ansible-playbook
# or with command line flags. ansible will read ANSIBLE_CONFIG,
# ansible.cfg in the current working directory, .ansible.cfg in
# the home directory or /etc/ansible/ansible.cfg, whichever it
# finds first
[defaults] # some basic default values…
#inventory      = /etc/ansible/hosts
#library        = /usr/share/my_modules/
#module_utils   = /usr/share/my_module_utils/
#remote_tmp     = ~/.ansible/tmp
#local_tmp      = ~/.ansible/tmp
#forks          = 5
#poll_interval  = 15
#sudo_user      = root
#ask_sudo_pass = True
#ask_pass      = False

Write your first Playbook using YAML files:-

Ansible playbooks are a way to use commands to do some operations on remote computers in a scripted manner. Instead of using Ansible commands individually to remote computers, you can configure entire deployments by passing it as scripts to one or more systems.

Each playbook contains one or more plays, which map hosts to a certain function. Ansible does this through tasks, which are basically module calls.

YAML is sensitive and you need to be cognizant about using spaces. TABs are not allowed.  Characters should start exactly after the previous parameter starts. It contains three sections.

  • Host Declaration
  • Variable declaration (optional)
  • Action/Tasks declaration

For instance, to create a basic apache web server following tasks are needed.

  • Install httpd package
  • Configure httpd service
  • Start and enable httpd service

So the YAML file can look like the one below.

[root@ansiblenode ~]# vi install.yml

– hosts: all
– name: Install httpd Package
yum: name=httpd state=latest
– name: Copy httpd configuration file
copy: src=/data/httpd.original dest=/etc/httpd/conf/httpd.conf
– name: Start and Enable httpd service
service: name=httpd state=restarted enabled=yes

About Nimesa

Nimesa is enterprise-class Application-Aware data protection, cost management & copy data management solution for applications running on AWS. It uses native AWS capabilities like EBS snapshots capabilities to automatically protect the environment. It provides simple policy-based lifecycle management of snapshots and clones of EC2 instances.

To know more of how to protect your environment using Nimesa refer to the previous blog

Try Nimesa for free