How to Install and Configure Ansible on CentOS 7

Ansible is an open-source automation tool. Ansible can help you on the platform, configuration management, application deployment, intra-service orchestration, and provisioning. It is very simple to setup and more powerful tool. In other words, it frees up time and increases efficiency. Nowadays most of the Automation tools require agent but Ansible just need SSH connection and Python (2.4 and more).

Install Ansible

See Also:

Step 1: Prerequisites

If your system is not registered with RedHat subscriptiton key then first you need to enable the epel repository to install Ansible.

# yum install epel-release

If your system is registered with Redhat subscription then execute mention command to enable the Ansible Engine repository.

# subscription-manager repos --enable rhel-7-server-ansible-2.6-rpms

Step 2: Install Ansible

Once repository has been installed on your system you are ready to install Ansible on server. Run the mention command to install Ansible.

# yum install ansible

After installed successfully, you can verify the version by executing below command.

# ansible --version
ansible 2.7.8
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

Step 3: Create Ansible User with Passwordless login

To perform any action or any deployment from Ansible server to remote server you need to create a Ansible user in all the machines and need to configure the passwordless login from Ansible server to all the remote host. Also normal user has an rights to switch to the root without password.

On Remote Hosts:
Create user in all the remote host with root rights.

# useradd ansible 
# passwd ansible

Edit sudoers file and add the mention line.

# vim /etc/sudoers
ansible    ALL=(ALL)      NOPASSWD: ALL

On Ansible Server:
Follow mention steps on Ansible server.

# useradd ansible
# passwd ansible
# su - ansible
# ssh-keygen -t rsa
# ssh-copy-id ansible@remote-host-IP

After copying the SSH key to remote host, passwordless configuration has been completed from Ansible server to remote host.

# ssh ansible@remote-host-IP

Now you are ready to use Ansible automation tools. Here is few more configuration for Ansible. Edit Ansible configuration file and do the changes as per your requirement. I am just mentioning my configuration.

# vim /etc/ansible/ansible.cfg
inventory      = /opt/ansible/hosts
roles_path = /opt/ansible/roles
timeout = 300
remote_user = ansible
log_path = /var/log/ansible/ansible.log

[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False

Reference: Ansible Playbook Official Website

Enjoy it!

No Responses

Leave a Reply

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.