In our first post on Ansible, we will learn how to install Ansible on Ubuntu / CentOS / RHEL . In the world of IT automation tools, Ansible name is famous among system admins and developers. Ansible can be used in cloud provisioning, configuration management, application deployment, intra-service orchestration and other automation needs.
Features of Ansible
We tried to place some basic features of Ansible here so that in first step everything should look simple and not confused .
1. Ansible is agentless and use SSH to connect with client machine.
2. Ansible configuration files uses the YAML format.
3. Ansible runs with its module library and orchestrate the multiple nodes exist in network.
4. Ansible knows about the host address information through its inventory file.
NOTE: Here, we are describing installation of anisible in 3 different section. Hence, select the section as per your Operating system and best suited for you.
Install Ansible with pip on Ubuntu / CentOS / RHEL
I personally like to go with pip installation method because we have to create complete Ansible file hierarchy from scratch.
(A) First install pip into your system. Read our previous post on – How to install pip on CentOS / RHEL / Ubuntu / Debian, where you will find installing pip in various Operating System versions.
(B) Installing ansible with pip command.
On CentOS / RHEL / Ubuntu / Debian , use below command to install Ansible via pip.
sudo pip install ansible
Install Ansible on Ubuntu with apt-get command
To install latest Ansible on Ubuntu system, use the below given command.
In Ubuntu 14.04 LTS or below
sudo apt-get install software-properties-common sudo apt-add-repository ppa:ansible/ansible sudo apt-get update sudo apt-get install ansible
In Ubuntu 16.04 LTS or above
sudo apt install software-properties-common sudo apt-add-repository ppa:ansible/ansible sudo apt update sudo apt install ansible
After installation, the /etc/ansible will be created and have two files i.e anisible.cfg and hosts .
Given below is reference from our system.
sharad@ubuntu:~$ ls -l /etc/ansible/ total 16 -rw-r--r-- 1 root root 8629 Jun 26 05:55 ansible.cfg -rw-r--r-- 1 root root 965 Jun 26 05:55 hosts sharad@ubuntu:~$
Install Ansible on CentOS / RHEL
To install Ansible on CentOS/RHEL , first you have to install EPEL repo into your system.
1. For CentOS 7 / RHEL 7 : Install EPEL repo on CentOS 7 and RHEL 7
2. For CentOS 6.x, 5.x / RHEL 6.x, 5.x : Install EPEL repo in CentOS 5.x , 6.x / RHEL 5.x, 6.x / Scientific Linux
Once you install the EPEL repo, you only have to hit the command –
sudo yum install ansible
After installation, you will see 2 files and 1 directory inside /etc/ansible .
See given below reference from our system .
[root@localhost ~]# ls -lhrt /etc/ansible/ total 16K drwxr-xr-x 2 root root 6 Jun 25 17:11 roles -rw-r--r-- 1 root root 965 Jun 25 17:11 hosts -rw-r--r-- 1 root root 8.5K Jun 25 17:11 ansible.cfg [root@localhost ~]#
Here, in this section we will cover frequently asked question which you may be thinking about.
1. In this post, we have seen hosts file. What is it ?
Answer : This is Ansible inventory file. by default, it comes with examples hence suggest to take the backup and create your own new hosts file inside /etc/ansible.
2. In this post, we have found also found ansible.cfg file. What it do ?
Answer : It is comprised of ansible variables . Hence, we suggest you to read the commented and uncommented ansible variables written in this file.
3. In CentOS / RHEL ansible installation, what this roles directory do ?
Answer: By defaulr this roles directory is empty . But here, we can define the ansible role. You have to read our upcoming ansible tutorials where we will also write about ansible roles and playbooks.