Ansible Installation Guide
This is the first hands-on lesson in the course. By the end of it, you will have Ansible installed on your machine and will have confirmed it is working. The installation process takes fifteen to thirty minutes depending on your operating system. Follow every step carefully and do not skip the verification steps — confirming a correct installation now saves hours of debugging later.
Choosing Your Control Node Operating System
Ansible runs on any Unix-like operating system. Your control node will be one of the following:
- Ubuntu or Debian Linux — The most common choice and the one with the best-documented installation path
- Red Hat Enterprise Linux, CentOS, Fedora, or Rocky Linux — Excellent support given Red Hat's ownership of Ansible
- macOS — Fully supported via Homebrew or pip; ideal for developers working on Macs
- Windows Subsystem for Linux (WSL) — The recommended approach for Windows users; install Ubuntu via WSL and follow the Ubuntu instructions
Installing Ansible on Ubuntu and Debian
Ubuntu is the most common Linux distribution for learning environments. The following commands install the latest stable version of Ansible using the official PPA (Personal Package Archive) maintained by the Ansible project.
Open a terminal and run these commands in order:
sudo apt update sudo apt install -y software-properties-common sudo add-apt-repository --yes --update ppa:ansible/ansible sudo apt install -y ansible
The ppa:ansible/ansible PPA ensures you receive Ansible updates through the standard apt package manager. This is the recommended installation method on Ubuntu because it makes updating Ansible as simple as sudo apt upgrade.
After installation, verify the version:
ansible --version
You should see output listing the Ansible version, Python version, and configuration file path. If you see a version number, the installation was successful.
Installing Ansible on Red Hat Enterprise Linux and CentOS
On RHEL-family systems, Ansible is available through the EPEL (Extra Packages for Enterprise Linux) repository:
sudo dnf install -y epel-release sudo dnf install -y ansible
On older CentOS 7 systems, replace dnf with yum. Verify the installation with ansible --version as above.
Installing Ansible on Fedora
Fedora includes Ansible in its standard repositories:
sudo dnf install -y ansible
Fedora typically ships a recent version of Ansible, so no additional repository configuration is required.
Installing Ansible on macOS
The recommended method on macOS is Homebrew, the package manager for macOS. If you do not have Homebrew installed, visit brew.sh and follow the installation instructions first.
With Homebrew installed, run:
brew install ansible
Homebrew installs Ansible and all its Python dependencies in an isolated environment, avoiding conflicts with system Python. Verify with ansible --version.
Alternatively, you can install Ansible via pip (Python's package manager):
pip3 install --user ansible
If you use pip, ensure that your Python user bin directory is in your PATH. On macOS, this is typically ~/Library/Python/3.x/bin. Add it to your shell profile if needed.
Installing Ansible on Windows via WSL
Ansible cannot run natively on Windows. The recommended approach is Windows Subsystem for Linux (WSL), which provides a genuine Linux environment inside Windows.
Enable WSL and install Ubuntu by opening PowerShell as Administrator and running:
wsl --install
After the installation completes and you restart your computer, open the Ubuntu application from the Start menu. You will be prompted to create a Linux username and password. Once inside the Ubuntu shell, follow the Ubuntu installation instructions above.
WSL integrates tightly with Windows — you can edit files in your Windows filesystem from within WSL and use Windows Terminal for a better experience. This setup is fully functional for all exercises in this course.
Installing via pip in a Virtual Environment (Advanced)
For teams that need precise version control over their Ansible installation, installing inside a Python virtual environment is best practice:
python3 -m venv ansible-env source ansible-env/bin/activate pip install ansible ansible --version
Virtual environments isolate Ansible and its dependencies from system Python packages, preventing version conflicts. This approach is particularly valuable in CI/CD pipelines where reproducibility is critical.
Configuring ansible.cfg
After installation, create a basic configuration file for your working environment. In your project directory, create a file called ansible.cfg:
[defaults] inventory = ./inventory.ini remote_user = ubuntu private_key_file = ~/.ssh/id_rsa host_key_checking = False
This configuration tells Ansible to use a local inventory.ini file, connect as the ubuntu user using your default SSH key, and skip strict host key verification (acceptable in a lab environment; always enable host key checking in production).
Verifying Your Installation
Run the following commands to confirm everything is working:
ansible --version ansible-playbook --version ansible-doc ping
The first two commands confirm the core tools are installed. The third command opens the documentation for the ping module, which confirms that Ansible's module library is accessible. Press q to exit the documentation viewer.
Common Installation Problems and Solutions
Problem: "ansible: command not found" after installation
The Ansible binaries are not in your PATH. If you installed via pip, add the Python user bin directory to your PATH. On macOS, run echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc.
Problem: Python version conflicts
Ansible requires Python 3.8 or later. If your system has multiple Python versions, ensure that pip is installing for the correct version. Use python3 --version to check. Consider using a virtual environment to avoid conflicts.
Problem: Permission denied during installation
Use sudo for system-wide package manager installations. Never use sudo pip install — it can corrupt system Python. Use pip with the --user flag or a virtual environment instead.
Try This: Confirm Your Installation
Run ansible --version and copy the output into a text file. Note the Python version, config file location, and ansible version. This snapshot documents your environment baseline — a habit that saves significant debugging time when things go wrong later.
Summary
Ansible can be installed on Ubuntu, Debian, RHEL-family systems, macOS, and Windows via WSL using native package managers or pip. The ansible.cfg file controls the working environment. Verifying the installation with ansible --version and ansible-doc confirms a correct setup before proceeding to connect to managed nodes.
