Ansible Overview
What is Ansible
Ansible is a configuration management tool used to automate configuration management, application deployment, infrastructure provisioning and orchestration
Key Features of Ansible
Ansible is agentless i.e it doesn’t require any program to be installed on target systems for working on target systems
Ansible is a declarative language i.e you just need to know what your desired state is and how to reach that state is taken care of ansible
Ansible follows idempotent execution i.e the ansible checks the state of the system and applies changes only if necessary
Benefits of Ansible
Ansible uses YAML format which is easy to read
Ansible can handle large and complex ecosystems efficiently
Ansible can manage heterogeneous environments having multiple different operating systems efficiently
Installing Ansible
Prerequisites
A Virtual Machine or an EC2 instance with an EPEL repository
# Installing EPEL Release
sudo yum install <https://dl.fedoraproject.ortg/pub/epel/epel-release-latest-9.noarch.rpm> -y
Installation and Configuration
Installing Ansible
sudo yum install ansible -y
Verifying ansible installation
sudo ansible --version
Creating a new user for managing ansible in both master and target and giving sudo permissions
# Creating ansible user
sudo useradd ansadmin
# Creating password for ansible user
sudo passwd ansadmin
# Giving ansible user admin priviliges by adding them into visudo file
sudo visudo
# Add below line in the sudoers or visudo file
ansadmin ALL=(ALL) NOPASSWD:ALL
Enabling password-based authentication for login to the Ansible server through SSH if you are using an EC2 instance, you can also use key-based authentication if you require
# Changing no to yes in PasswordAuthentication parameter in sshd_config file
sudo sed -ie 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
# Restarting SSH service for changes to take place
sudo systemctl restart sshd
Enabling password-less authentication between Ansible master and slave
# Login as ansible user
sudo su ansadmin
# Generate SSH key
ssh-keygen
# Copying SSH key to target system
ssh-copy-id <target-server-IP>
Giving ownership of /etc/ansible
to ansadmin user
sudo chown -R ansadmin:ansadmin /etc/ansible
Adding target server IP to ansible inventory file
echo "<target-server-IP>" > /etc/ansible/hosts
For checking the connectivity between the ansible master and the target system
# Pinging ansible target system
ansible all -m ping