Learn how to install Ansible on Rocky Linux 8 with this comprehensive guide. Follow our step-by-step instructions to set up Ansible, configure your environment, and automate your IT infrastructure efficiently. #centlinux #linux #ansible
Table of Contents
What is Ansible Automation Platform?
Ansible is an open-source automation tool that simplifies the process of IT automation, configuration management, and application deployment. It enables you to automate repetitive tasks, manage configurations, and orchestrate complex workflows across multiple servers or network devices. (Ansible Official Website)
Here are some key features and aspects of Ansible:
- Agentless: Ansible operates in an agentless manner, meaning it doesn’t require any agents or daemons to be installed on the managed hosts. It communicates with remote machines through SSH, making it lightweight and easy to set up.
- Infrastructure as Code (IaC): Ansible allows you to define infrastructure configurations, application deployments, and workflows as code using YAML syntax. This enables version control, collaboration, and repeatability of infrastructure changes.
- Playbooks and Roles: Ansible uses playbooks, which are YAML files containing a series of tasks to be executed on remote hosts. Playbooks can be organized into roles, allowing for modular and reusable configurations.
- Idempotent Execution: Ansible ensures idempotent execution, meaning running the same playbook multiple times will result in the same desired state, regardless of the initial state of the system. This helps maintain consistency and predictability in infrastructure management.
- Extensibility: Ansible is highly extensible, with support for a wide range of modules and plugins. You can extend its functionality by writing custom modules or using community-contributed modules to integrate with various systems and services.
- Orchestration: Ansible can orchestrate complex workflows across multiple hosts, including tasks such as rolling updates, blue-green deployments, and multi-tier application deployments.
- Integration: Ansible integrates seamlessly with other tools and technologies commonly used in the DevOps ecosystem, such as version control systems (e.g., Git), continuous integration/continuous deployment (CI/CD) pipelines, cloud platforms, and monitoring systems.
Overall, Ansible provides a simple, yet powerful way to automate IT operations, streamline configuration management, and accelerate application deployments, making it a popular choice for DevOps teams and system administrators.
Read Also: How to install Ansible on Rocky Linux 9

Ansible vs Terraform
Ansible and Terraform are both powerful tools used in DevOps and infrastructure automation, but they serve different purposes and have distinct features:
Ansible
- Description: Ansible is a configuration management and automation tool that focuses on task execution and configuration management across multiple servers.
- Strengths:
- Agentless: Ansible doesn’t require any agents to be installed on remote systems, making it easy to set up and use.
- Simplicity: Ansible uses YAML syntax and is easy to learn, making it accessible to a wide range of users.
- Configuration Management: Ansible excels at managing configurations, deploying software, and orchestrating complex tasks across servers.
- Use Cases: Ansible is well-suited for tasks such as configuration management, application deployment, and ad-hoc task automation.
Terraform
- Description: Terraform is an infrastructure as code (IaC) tool that focuses on provisioning and managing infrastructure resources using declarative configuration files.
- Strengths:
- Infrastructure as Code: Terraform allows you to define infrastructure resources as code, enabling versioning, collaboration, and repeatability.
- Multi-Cloud Support: Terraform supports multiple cloud providers and infrastructure platforms, allowing you to manage resources across different environments.
- State Management: Terraform maintains a state file that tracks the current state of your infrastructure, making it easier to manage and update resources.
- Use Cases: Terraform is ideal for provisioning and managing cloud infrastructure, creating immutable infrastructure, and managing complex environments.
Read Also: How to install Terraform on Rocky Linux 10
Comparison
- Focus: Ansible focuses on configuration management and automation of tasks, while Terraform focuses on infrastructure provisioning and management.
- Approach: Ansible follows a procedural approach, where tasks are executed sequentially, while Terraform follows a declarative approach, where you define the desired state of your infrastructure.
- Complexity: Ansible is simpler to learn and use, making it suitable for a wide range of tasks and users. Terraform, while more complex, offers powerful features for managing infrastructure at scale and across multiple providers.
- Use Cases: Ansible is often used for managing configurations, deploying applications, and automating routine tasks. Terraform is typically used for provisioning cloud resources, managing infrastructure, and creating repeatable infrastructure deployments.
In summary, while both Ansible and Terraform are valuable tools in the DevOps toolkit, they serve different purposes and are often used together to achieve comprehensive automation and infrastructure management.
Environment Specification
We are using a minimal Rocky Linux 8 virtual machine with following specifications.
- CPU – 3.4 Ghz (2 cores)
- Memory – 2 GB
- Storage – 20 GB
- Operating System – Rocky Linux 8.5 (Green Obsidian)
- Hostname – ansible-01.centlinux.com
- IP Address – 192.168.116.129 /24
For setting up your Ansible environment on Rocky Linux 8, it’s highly recommended to use either a dedicated Mini PC or a reliable VPS like Bluehost. A Mini PC offers a compact, energy-efficient, and powerful way to create a home lab where you can safely experiment with Linux server configurations and automation workflows using Ansible.
[Limited Time Mini PC Offers – Click and Save!]
Alternatively, a Bluehost VPS provides scalable cloud-based resources that enable you to deploy and manage Rocky Linux instances with ease, perfect for remote testing and continuous learning.
[Try Bluehost VPS Now – Perfect for Linux & DevOps Enthusiasts!]
Both options are ideal for hands-on practice and refining your skills in Linux server administration. If you’re interested, check out the Mini PC and Bluehost VPS links below to get started with your own lab setup.
Disclaimer: This post contains affiliate links. If you purchase through these links, we may earn a small commission at no extra cost to you.
Set Hostname of Linux Server
By using a ssh client, connect with your Rocky Linux 8 server as root user.
Execute the following command on Linux bash prompt to set a proper hostname for your Ansible Control Node.
hostnamectl set-hostname ansible-01.centlinux.comUpdate Linux Software Packages
Build cache for yum repositories.
dnf makecacheUpdate your Linux software packages by using dnf command.
dnf update -yCheck the Linux Kernel and Operating System versions.
uname -r
cat /etc/rocky-releaseOutput:
4.18.0-348.12.2.el8_5.x86_64
Rocky Linux release 8.5 (Green Obsidian)
Install EPEL Yum Repository
Ansible requires some packages from EPEL yum repository. Therefore, you have to install it before moving forward.
dnf install -y epel-releaseBuild cache for newly installed yum repositories.
dnf makecacheOutput:
Rocky Linux 8 - AppStream 2.1 kB/s | 4.8 kB 00:02
Rocky Linux 8 - BaseOS 2.5 kB/s | 4.3 kB 00:01
Rocky Linux 8 - Extras 4.0 kB/s | 12 kB 00:02
Extra Packages for Enterprise Linux 8 - x86_64 465 kB/s | 11 MB 00:24
Extra Packages for Enterprise Linux Modular 8 - 256 kB/s | 979 kB 00:03
Metadata cache created.
Install Python3 on Rocky Linux 8
Ansible is written in Python programming language. Therefore to install Ansible on Rocky Linux, you are also required to add Python3 language support along with pip3 (Python Package Manager) and required plugins.
dnf install -y python3 python3-pipAfter successful installation of Python3 software, check the version of python3 command.
python3 -VOutput:
Python 3.6.8
The installed version of pip3 may not be the latest one, Therefore, you should upgrade it by using Python Package Manager.
pip3 install --upgrade pipInstall Ansible on Rocky Linux 8
You can now install Ansible on Rocky Linux from EPEL yum repository by executing the dnf command.
dnf install -y ansibleAfter successful installation, verify the version of ansible command that was being installed in previous step.
ansible --versionOutput:
ansible 2.9.27
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, Nov 9 2021, 14:44:26) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
Ansible Command Examples
Generate the SSH Key for your user on Ansible machine.
ssh-keygenOutput:
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ac0BBY4e3updr1ZWgBo3h1uvOGzupr1gPPg3FYJtT3k root@ansible-01.centlinux.com
The key's randomart image is:
+---[RSA 3072]----+
| oo.o |
| o..= + |
| o .*.= + |
| o oo+=.+ E |
| o Soo= = |
| = = * |
| o =o.= |
| . + =*. |
| . +*=+. |
+----[SHA256]-----+
Copy the generated SSH Key to the target Linux machine by using the ssh-copy-id command.
ssh-copy-id root@192.168.116.128Output:
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.116.128 (192.168.116.128)' can't be established.
ECDSA key fingerprint is SHA256:P6+LBv2gk76hgvcQq7j5aaHHh48/I/f50xTD/GhWqBc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.116.128's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.116.128'"
and check to make sure that only the key(s) you wanted were added.
Create an Inventory file for Ansible and add an entry for your target Linux machine as follows.
echo "192.168.116.128 ansible_ssh_user=root" >> hostsPing the target Linux machine using ansible command to check connectivity.
ansible -i hosts 192.168.116.128 -m pingOutput:
192.168.116.128 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}Execute the following command to read a log file from the target Linux machine.
ansible -i hosts 192.168.116.128 -m command -a "tail /var/log/firewalld"Output:
192.168.116.128 | CHANGED | rc=0 >>
2022-02-20 20:12:06 WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Please consider disabling it now.
2022-02-25 21:21:42 WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Please consider disabling it now.
This is Adhoc command execution mode of Ansible. You can execute any Linux command on the target machine by using above syntax.
Final Thoughts
Installing Ansible on Rocky Linux 8 opens the door to streamlined IT automation and enhanced productivity. With our guide, you now have the foundation to automate your infrastructure and workflows effectively. If you require further assistance or customized configurations, I offer professional services to help you harness the full potential of Ansible.
From setting up scalable AWS solutions to managing complex Linux environments, I’ve got you covered. Visit my Freelancer profile to get started.
FAQs
Q1: Can I install Ansible on Rocky Linux 8 without root privileges?
A1: No, installing Ansible requires root or sudo privileges because it needs to install packages and dependencies system-wide.
Q2: Is EPEL repository required to install Ansible on Rocky Linux 8?
A2: Yes, the Extra Packages for Enterprise Linux (EPEL) repository is needed since Ansible is not included in Rocky Linux’s default repos.
Q3: Can Ansible be installed without internet access on Rocky Linux 8?
A3: Yes, but you must manually download Ansible packages and dependencies on another machine and transfer them for offline installation.
Q4: Will installing Ansible affect existing Python versions on my Rocky Linux 8?
A4: No, Ansible uses Python 3 which comes pre-installed on Rocky Linux 8, so it won’t overwrite existing Python versions.
Q5: How do I verify Ansible was installed correctly after setup?
A5: Run ansible --version in the terminal; if it shows version details without error, the installation was successful.
Recommended Courses
If you’re new to DevOps and want to build a strong foundation in automation, Ansible for the Absolute Beginner – Hands-On – DevOps by Mumshad Mannambeth is the perfect place to start. This highly-rated course walks you through the core concepts of Ansible with practical, step-by-step exercises, making it easy to learn even if you have zero prior experience.
By the end, you’ll have the confidence to automate real-world tasks and accelerate your DevOps journey. Don’t wait until you’re left behind in the job market—invest in your skills today and unlock future opportunities.
Disclaimer: This post contains affiliate links. If you purchase through these links, I may earn a small commission at no additional cost to you.

Leave a Reply
Please log in to post a comment.