Skip to content

Installing Ansible

Requirements

Python Requirements

  • Python 3.9 or later
  • pip (Python package manager)
  • virtualenv (recommended)

Operating System Support

  • Control Node: Linux, macOS, WSL2
  • Managed Nodes: Linux, Windows, macOS

Installation Methods

Using pip

# Create virtual environment
python -m venv ansible-env
source ansible-env/bin/activate

# Install Ansible
pip install ansible

# Verify installation
ansible --version

Using Package Managers

Ubuntu/Debian

# Add Ansible repository
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible

# Install Ansible
sudo apt install ansible

RHEL/CentOS

# Enable EPEL repository
sudo dnf install epel-release

# Install Ansible
sudo dnf install ansible

macOS

# Using Homebrew
brew install ansible

Post-Installation Setup

Configuration File

Create or edit /etc/ansible/ansible.cfg or ~/.ansible.cfg:

[defaults]
inventory = ./inventory
remote_user = ansible
host_key_checking = False
timeout = 30

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

SSH Key Setup

# Generate SSH key
ssh-keygen -t ed25519 -C "ansible"

# Copy key to remote hosts
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@remote-host

Testing Installation

Verify Connectivity

# Create inventory file
echo "localhost ansible_connection=local" > inventory

# Test connection
ansible all -i inventory -m ping

Basic Command Test

# Run a simple command
ansible all -i inventory -m command -a "uptime"

Next Steps

  1. Configure your inventory
  2. Write your first playbook
  3. Learn about modules
  4. Understand variables and facts

Troubleshooting

Common Issues

Python Not Found

# Install Python on remote hosts
sudo apt install python3
sudo ln -s /usr/bin/python3 /usr/bin/python

SSH Connection Issues

# Enable SSH debugging
ANSIBLE_DEBUG=1 ansible all -i inventory -m ping -vvv

Permission Problems

# Configure sudoers
echo "ansible ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/ansible

Why This Matters

Getting Ansible installed cleanly with an isolated Python environment and working SSH access prevents a large class of setup problems later. A reliable control-node baseline makes tutorials and CI/CD reproducible.

Common Pitfalls

  • Mixing system Python and virtualenvs leading to conflicting packages.
  • Missing build tools when installing extras (e.g., cryptography dependencies).
  • SSH key permissions too open (private key should be 600).
  • On Windows, not using WSL2 for the control node (native Windows control nodes are not supported).

Quick Checklist

  • Python 3.9+ and pip available.
  • Virtualenv created and activated before pip install ansible.
  • ansible --version shows expected python and config path.
  • SSH keys generated and copied; private key has chmod 600.
  • ansible all -i inventory -m ping succeeds for at least one host.

Next Steps

  • Configure your inventory structure for environments.
  • Create your first playbook and run with --syntax-check and --check.
  • Add ansible-lint and pre-commit hooks to catch issues early.