Installing Ansible on Centos

In this article, Let’s learn the steps of installing Ansible on Centos. If you want to learn about Ansible Fundamentals and Architecture, please refer to this article.

Installing Ansible on Centos

Update the system with the latest packages

sudo yum -y update

Install EPEL (Extra Packages for Enterprise Linux) repository.

sudo yum -y install epel-repo

Update the repository cache

sudo yum -y update

Install Ansible

sudo yum -y installansible

Check Ansible Version

ansible --version

Setup users for target nodes

Create a user to be used by Ansible for connecting to target nodes. These users need to be created in all the target nodes which we want to manage.

useradd -m ansible

Provide sudo access to the user.

echo "ansible ALL=(ALL) NOPASSWD: ALL" /etc/sudoers

Setup a password for Ansible user

passwd <username>

Generate ssh key for ansible user on the Control Node.

ssh-keygen

Copy ssh ID to all the target nodes.

ssh-copy-id target_node

Check if we can connect to Target Nodes from Control Node.

ssh ansible@target_node

👏👏 Congratulations! 👏👏

You have installed Ansible and set it up to connect to target nodes. 🙌

Now, Let’s check if Ansible can connect to target nodes:

Create an inventory file called hosts and add below lines to it

<target_node_ip_or_hostname> ansible_user=ansible
<target_node_ip_or_hostname> ansible_user=ansible

Run ansible ping command and observe the output

ansible all -i hosts -m "ping"

Leave a Comment

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

Scroll to Top