Ansible can be installed on a large variety of systems, but most people and companies run it on Linux hosts. Small companies and startups (with only a few administrators) do not dedicate a server for it, rather they use the admin workstations or notebooks. When a company grows and more people work on the environment they dedicate a server to these operations, and Ansible can scale well. In this article we go through the different alternative methods to install Ansible.
Previous article in the course: Automation, Configuration Management, Infrastructure as Code
Next article in the course: [soon, on Tuesday]
The first and initially the most obvious method to install an Ansible control machine is using the operating system’s package manager. Ansible is part of many popular distributions like Fedora, Debian, Ubuntu and Arch. For specific installation recommendations follow the link to the documentation.
Specific OS packages
Installing Ansible on specific operating systems
Debian derivatives
To install Ansible on Debian based systems, the process involves using the APT (Advanced Package Tool) package manager. This method requires root privileges or sudo permissions.
Start by ensuring our system is updated:
sudo apt update
Once the system is up to date, you can proceed to install the Ansible package:
sudo apt install ansible
APT will handle the resolution of dependencies and retrieve the required packages for Ansible installation. After the installation is complete, you can verify the installed Ansible version by running:
ansible --version
This command provides detailed information about the installed Ansible version.
Red Hat derivatives
To install Ansible on Rocky Linux 9 using YUM or DNF, you have to follow these steps for a seamless and efficient deployment. This method requires root privileges or sudo permissions.
Add the EPEL repository to the system.
sudo dnf install epel-release
Begin by ensuring that our system is updated with the latest packages using the following command:
sudo dnf update
Once the system is up to date, you can proceed to install Ansible with the DNF package manager:
sudo dnf install ansible
DNF will automatically resolve dependencies and download the necessary packages for Ansible installation. After the installation process is complete, you can verify the successful installation and check the installed Ansible version by executing:
ansible --version
This command will display detailed information about the installed Ansible version.
Python PIP
Installing and upgrading Ansible with pip
For a more flexible and isolated installation of Ansible, utilizing Python’s virtual environment (venv) and the pip package manager offers a simple approach. To install the requirements with a package manager it requires root privileges or sudo rights. This installation method can be used in any distribution that supports Python packages.
Begin by ensuring that Python and the venv module are installed on your system:
sudo apt update
sudo apt install python3-venv
Once the prerequisites are in place, exit root and as an ordinary user create a virtual environment to encapsulate the Ansible installation in a project directory (like /home/<user>/ansible
):
python3 -m venv .venv
This command creates a Python virtual environment.
Activate the environment (in BASH issue the following command):
source .ansible-venv/bin/activate
With the virtual environment activated, proceed to install Ansible using pip:
pip install ansible
This ensures that Ansible and its dependencies are installed within the isolated environment.
To confirm the installation and check the Ansible version, use:
ansible --version
This approach not only facilitates Ansible installation but also ensures a clean, isolated environment, allowing for better management of dependencies and versions within your projects.
Once done, you can deactivate the virtual environment:
deactivate
This leaves your system environment unaffected by the installed Ansible version, providing a controlled and efficient deployment.
The process of installing Ansible with pip in a virtual environment (venv) on Rocky Linux 9 is conceptually similar to the procedure outlined for Debian. The base Rocky installation already contains the venv module. You can just create the ansible
project directory and the virtual environment in it right away.
Now you are ready to take the first steps with Ansible.
If you want to discuss the topic with other technology-minded people, join my Discord: https://discord.gg/YbSYGsQYES
Now we have an IRC channel as well: irc.libera.chat / #tomsitcafe
One thought on “Ansible Basics 02: Installing Ansible”