Setting up Ansible on a Linux machine involves the following steps. Current stable version: Ansible-core 2.20.2 (released January 29, 2026)
Before installing Ansible, ensure your system meets the following requirements:
Before installing Ansible, update the system’s package list.
sudo apt update # For Ubuntu/Debian
sudo dnf update # For Fedora/Rocky Linux/AlmaLinux
sudo yum update # For older RHEL/CentOS versions
Multiple installation methods are available depending on your needs:
# Install pip if not already installed
sudo apt install python3-pip # For Ubuntu/Debian
sudo dnf install python3-pip # For Fedora/Rocky Linux/AlmaLinux
sudo yum install python3-pip # For RHEL/CentOS
# Create a virtual environment (recommended)
python3 -m venv ansible-env
source ansible-env/bin/activate
pip install --upgrade pip
pip install ansible
# To activate the environment in future sessions:
# source ansible-env/bin/activate
# Install pipx
sudo apt install pipx # For Ubuntu/Debian
sudo dnf install pipx # For Fedora/Rocky Linux/AlmaLinux
# For other systems: python3 -m pip install --user pipx
# Install and run Ansible with pipx
pipx install ansible
# Install from default repositories (may not be the latest version)
sudo apt update
sudo apt install ansible
# OR install from Ansible PPA for newer versions
sudo apt install software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt update
sudo apt install ansible
# For RHEL/CentOS 8+ and Fedora: Enable EPEL repository
sudo dnf install epel-release # For RHEL/CentOS
# EPEL is included by default in Fedora
# Install Ansible
sudo dnf install ansible # For Fedora/Rocky Linux/AlmaLinux/RHEL/CentOS 8+
sudo yum install ansible # For older RHEL/CentOS versions
Check the Ansible version to confirm the installation was successful:
ansible --version
You should see output similar to:
ansible [core 2.20.2]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /path/to/ansible/lib/python3.x/site-packages/ansible
executable location = /path/to/ansible/bin/ansible
python version = 3.12.x
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 -b 4096 -C "ansible@control-node"
# Press Enter to accept defaults, optionally set a passphrase
Copy the SSH key to remote machines:
ssh-copy-id user@remote_server_ip
# Or for a specific key file:
ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote_server_ip
Test SSH connection:
ssh user@remote_server_ip
Ansible manages machines via an inventory file. You can create a custom inventory file or use the default location at /etc/ansible/hosts.
To create a custom inventory file in your home directory:
mkdir -p ~/ansible
nano ~/ansible/inventory
Add remote servers in this format:
[webservers]
web1.example.com ansible_host=192.168.1.10
web2.example.com ansible_host=192.168.1.11
[databases]
db1.example.com ansible_host=192.168.1.20
db2.example.com ansible_host=192.168.1.21
[production:children]
webservers
databases
[all:vars]
ansible_user=ansible_user
ansible_ssh_private_key_file=~/.ssh/id_rsa
ansible_python_interpreter=/usr/bin/python3
Create a custom ansible.cfg file to override default settings:
# Create ansible.cfg in your project directory
cat > ~/ansible/ansible.cfg << EOF
[defaults]
inventory = ~/ansible/inventory
remote_user = ansible_user
host_key_checking = False
gathering = smart
fact_caching = memory
timeout = 30
forks = 20
stdout_callback = yaml
interpreter_python = auto_silent
[inventory]
enable_plugins = host_list, script, auto, yaml, ini, toml
[privilege_escalation]
become = True
become_method = sudo
become_user = root
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s
pipelining = True
EOF
You can now test your Ansible setup by pinging your remote servers:
# Test with specified inventory
ansible all -i ~/ansible/inventory -m ping
# Test with default inventory (if configured in ansible.cfg)
ansible all -m ping
# Test specific group
ansible webservers -i ~/ansible/inventory -m ping
# Test specific host
ansible web1.example.com -i ~/ansible/inventory -m ping
If everything is set up correctly, you should see a pong response from each server.
Ansible Collections are a distribution format that packages Ansible content. Install commonly used collections:
# Install community collections
ansible-galaxy collection install community.general
ansible-galaxy collection install community.docker
ansible-galaxy collection install ansible.posix
# Install cloud provider collections
ansible-galaxy collection install amazon.aws
ansible-galaxy collection install azure.azcollection
ansible-galaxy collection install google.cloud
ansible_python_interpreterAny questions?
Feel free to contact us. Find all contact information on our contact page.