Ansible is an open source IT automation engine that automates provisioning, configuration management, application deployment, orchestration, and many other IT processes. It enables infrastructure as code. Ansible automates and simplifies repetitive, complex, and tedious operations. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows.
Ansible itself is written in Python and has a fairly minimal learning curve. Ansible follows a simple setup procedure and does not depend on any additional software, servers or client daemons. It manages nodes over SSH and is parallel by default.
In this guide, we are going to learn how to Install and Configure Ansible on Rocky Linux/CentOS 8.
Related content
- How to Install and Configure Ansible on Rocky/Alma Linux 9
- How to Install Python 2 and Python 3 on Rocky Linux/Centos 8
- How to Install Python 2 and Python 3 on Fedora 35
- How to Install and Configure Ansible on Fedora 35
Prerequisites
To follow along, ensure you have:
- An up to date Rocky Linux/Centos 8 Server
- Access to the internet
- Knowledge of Linux terminal
Ensure that the OS packages are up to date
Before proceeding, it is always recommended to have the system and the installed packages updated.
Use this command to ensure that the system packages are up to date:
|
|
Installing Python on Rocky Linux/Centos 8 Server
Ansible is written in Python. Since python programs are interpreted, they always need the python runtime available for them to run. Ansible is not an exception, we need Python to exist for us to run Ansible. Ansible works for both Python 2 and Python 3.
Use this to install python3 on the server:
|
|
Pip is a package manager for Python. We can use pip to manage python python packages and their dependencies. We will also need pip to Install ansible. Use these commands to install pip:
|
|
It is also recommended to have the latest version of pip installed. Use this command to upgrade pip
|
|
Installing Ansible
There are two ways we can use to install Ansible in our system.
Install ansible Using EPEL repo
Extra Packages for Enterprise Linux (or EPEL) is a Fedora Special Interest Group that creates, maintains, and manages a high quality set of additional packages for Enterprise Linux. Add EPEL repository to your Rocky Linux/Centos 8 system using this command:
|
|
We can then install ansible that is provided in the EPEL repo using this command:
|
|
Check the version of Ansible installed on your system using this command:
|
|
Install ansible using pip
Pip can be used to install ansible on our system.
|
|
Since I already installed ansible in my case, I get this
|
|
Testing Ansible installation
Ansible uses ssh to connect and execute commands on the remote server. So for Ansible to work, we need to ensure that we can connect to the remote server using ssh.
To perform password less ssh to the remote server, use this command to generate ssh key:
|
|
The copy the id to the remote server:
|
|
Now create an inventory file:
|
|
With this content:
|
|
Use ping module to test ansible:
|
|
For commands that need sudo, pass the option --ask-become-pass
. This will ask for privilege escalation password. This may require installation of the sshpass
program.
|
|
Conclusion
We have managed to install Ansible and test connection to a remote server in this guide.