Automation with Ansible



We all hate repetitive work right? Yes ofcourse we hate things and tasks that come and go round and round. That was a stupid question to ask 😊. Then also I asked because I know a tool which love repetitive work, Ansible 😍.

There are several scenarios in a Devops environment where people do repetitive tasks which can be automated. Like adding a new feature and rolling out the updated version of there product. This task may involve copying the new application to servers and restarting the servers one by one. This is a very common task which ops do and can be automated. When tasks get automated the entire process from development to deployment get accelerated. That acceleration can decrease the time required to roll out new updated version of the app from months to weeks or weeks to days or days to hours. Sounds cool 😎.

For doing automation there are many tools available like puppet, chef, saltstack and ansible. The key difference between ansible and all other automation tools is  ansible is agent less. Agent less in the sense we don't need to install a client software on every nodes in a network. Ansible can communicate and configure any nodes in a network using the default ssh. Now you might be thinking it can't be used for configuring windows machine. But yes it's possible in ansible by using a different connection module called winrm. The only requirement is powershell must be installed on windows machines.

In other automation tools like chef or puppet we need to install some client software to make a communication with the master node which we use to automate tasks.

Some common terminologies in ansible:

Playbooks : Set of plays
Play : Set of tasks
tasks : Tasks are like installing a package or restarting a service
roles: Roles are organized structure of playbook which are ready to share with  others 
modules : Modules are kind of functions for doing a particular task. For eg. to install a package we can do it with command module. But instead of using command module you can use yum or apt module depending on your linux flavour.
ansible-galaxy : Online repository of roles where we can share or download and install roles
ansible-vault : Addon tool for encrypting valuable informations like password
ansible-playbook : Tool which is used to run playbook
ansible-doc : Tool which can be used to search and read documentation of available modules eg: ansible-doc command


Ansible architecture

source: Internet

Installation of ansible

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

ansible localhost -m command -a whoami
 

After installation when you try the above statement on your terminal you can see it successfully show you the hostname. Here what ansible is doing it is making a local connection instead of ssh connection because the hostname which we are specified here is localhost. -m is for specifying the module to be used and we are using command module here. -a is for passing the arguments if any.

Hope you enjoyed reading about ansible. So lets start cooking something with ansible. Ansible + AWS?? Stay tuned 😎
 
- Thanks

Comments

  1. Good,a nice and simple introduction

    ReplyDelete
  2. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    rpa Training in Bangalore

    ReplyDelete

Post a Comment

Popular Posts