The Ansible tutorials will cover the following topics.
- What is Ansible?
- How to install Ansible?
- The Ansible architecture
- Configuration of Ansible
- How to work with Playbook in Ansible?
- How to work with Inventory Files in Ansible?
- How to work with modules in Ansible?
- How to develop test and release a playbook?
- How to take Ansible to Production?
- How to handle Errors in Ansible?
- How to Rollback in Ansible?
- How to work with Reporting in Ansible?
- How to create a custom module in Ansible?
- How to create provisioning for Docker?
- How to deploy Ansible in large organization?
- What is Ansible tower?
What is Ansible?
Ansible is a very simple IT automation engine that automate provisioning ,configuration, application deployment, intra service orchestration whose aim is to provide enlarge productivity. It is written in Python and can be installed as Linux machine only.
Ansible is the infrastructure automation tool. It can set up several built agents in continuous integration(CI) system. Using ansible building or rebuilding infrastructure is easy, fast and error free. All setup can be done by just one click. Ansible provides a fuel towards devops journey.The primary aim of configuration management is to provide machines to a denied state as fast as possible.
Other infrastructure automation tools are-
Infrastructure testing tools are: –
- Test kitchen
Provisioning tools are: –
Deployment tools are:-
- Thoughtworks Go
- Atlassion bamboo
Orchestration tools are
Monitoring tools are:-
- Nagi OS
Logging tools are:-
Ansible needs to be installed on a single machine which will manage your whole infrastructure.For remaining clients machine either we need their hostname or IP address.
Push and pull based mechanism
There are two mechanisms available.Pull based mechanism and push based mechanism.
In pull based mechanism,client will contact the server and check if any config applicable for the machine.If any, server will provide the client with the configuration or other details.
Puppet and chef follow pull based mechanism.Agent on the server periodically checks for the configuration information from central server.
In push based mechanism, server will push the applicable config/or other details to client if applicable without the agent.
Ansible follows push based mechanism.Central server pushes the configuration information on target client.
|Normal/ pull based|
|Responsible for providing the service||Access the server|
|Need some utility to access the server|
|Ansible/ push based|
|Ansible server config changes in server||No need to install some utility to access the server|
|The Architecture of Ansible|
|Agent Based System||Agentless system|
|These kind of system needs an external agent along with the dependencies.||No agent is required only a proper SSH daemon setup is required.|
|Agent based systems need to invoke the agent in order to run and pull the latest configuration .Either the agent runs as service or cron job.||These system pushes the configuration remotely without the agent.|
|Parallel agents execution may slow down the server. Serverless execution can make the process faster.||Parallel execution is faster as long as parallel execution count is lesser than SSH connection allowed count.|
|Agents installation and permissions are headache.||Only SSH based remote connection is required.|
Puppet needs agent on puppet server .Agent program needs some space and CPU prioritization.
Ansible by default runs on push mode but using ansible –pull, ansible provides an agent that can work as pull mode.To make default SSH connections faster, we can always enable control persist and pipeline mode.
Tools like chef, puppet are agent based and they by default work on pull mode. Using serverless chef and master less puppet we can scale up large machines.
Ansible tasks defined in the playbooks can execute sequentially by default. However, we can insert conditions and loops so that selective execution can happen.Ansible provides set of API s to run a script. Mostly when we create our own task set we call these APIs with the help of custom wrappers.All playbooks are written in YAML language. They are simple and declarative.Ansible can execute N threads in parallel.
Features of Ansible
- Open source
- Written on python so easy to read and extend(Built on top of python)
- Easy installation and configuration
- Highly scalable
- Agent less client connection
- SSM for secure connection
- Simple English Language confirmation setup
Who uses Ansible
If we want to push one software or patch or want to install some packages. Manual installation is very tedious and time consuming.They are error prone too. To simplify the process we can use Ansible.These activities can be done very easily by ansible script/command/playbook.
Below are the guys who uses Ansible
- System administrator
- Data engineers
- Devops Professionals
- Database administrator
- Network administrator
How to install Ansible?
Ansible software is available in EPEL repositories.Ansible does not come with normal unix or linux distribution.So we need to activate epel.In order to install Ansible, yum will try to contact internet and download the required software and other dependency files.
Prerequisites of Ansible
- SSH client(Open SSH)
Ansible system requirements for clients(node)
- 2 GB RAM
- 20 GB Hard disk
- os-RHEL/CENTOS/UBUNTU/ORACLE LINUX/HAC/BSD/Solaris/Windows OS
Ansible system requirements for ansible server
- LINUX(RHEL/CENTOS/ ORACLE LINUX)operating system.
- 4GB RAM
- 40 GB Hard disk space
- SSH(open SSH)
- Enabled EPEL repository for centos(6.8 or 7.2)
- Internet Connection
If you have an existing infrastructure but need a server version of Ansible,we can install Ansible with “pip”.Pip tool managesthe packages of python along with library.The advantage of Pip is that all ansible releases are pushed automatically.Hence no more manual updation is required.
After Git installation
PATH=/home/vagrant/ansible/bin:/usr/local/bin:/ bin:/usr/bin:/usr/loal/sbin:/usr/sbin:/sbin:/home/vagrant/bin. PYTHONPATH=/home/vagrant/ansible/lib MANPATH=/home/vagrant/ansible/docs/man
Once we have installed ‘Easy_install’we can further install the remaining packages.
>sudo easy_install pip // install pip.package
Then we need to install paramiko,PyYAML,jinja2 and httplib2
>Sudo pip install paramiko PyYAML,jinja2 and httplib2
This command will install all the other packages.