Setting up Ansible on a Linux machine involves the following steps:
Before installing Ansible, update the system’s package list.
sudo apt update # For Ubuntu/Debian
sudo yum update # For CentOS/RHEL
Ansible can be installed from the default repositories or by adding the official Ansible PPA.
Install the required dependencies:
sudo apt install software-properties-common
Add Ansible PPA:
sudo add-apt-repository --yes --update ppa:ansible/ansible
Install Ansible:
sudo apt install ansible
Enable the EPEL repository (Extra Packages for Enterprise Linux):
sudo yum install epel-release
Install Ansible:
sudo yum install ansible
Check the Ansible version to confirm the installation was successful:
ansible --version
Ansible uses SSH to connect to remote servers. You should have passwordless SSH access configured between your control node and the managed nodes.
Generate an SSH key (if you don’t already have one):
ssh-keygen -t rsa
Copy the SSH key to remote machines:
ssh-copy-id user@remote_server_ip
Ansible manages machines via an inventory file. By default, this file is located at /etc/ansible/hosts
.
To add remote servers, edit the file:
sudo nano /etc/ansible/hosts
Add remote servers in this format:
[webservers]
192.168.1.10
192.168.1.11
[databases]
192.168.1.20
You can now test your Ansible setup by pinging your remote servers:
ansible all -m ping
If everything is set up correctly, you should see a pong
response from each server.
Feel free to contact us. Find all contact information on our contact page.