What is Ansible
Ansible is a user-friendly, open-source automation platform with an agentless architecture. It simplifies IT tasks by using plain language Playbooks to describe infrastructure. Ansible connects to hosts via OpenSSH, executing tasks through temporary programs called modules. This agentless approach ensures efficiency and security, as no permanent agents or special security setups are required. This makes Ansible an adaptable and accessible tool for automating diverse workflows, allowing users to quickly achieve productivity without the need for special approvals or host deployments.
Ansible Concepts and Architecture
In the Ansible architecture, there are two sorts of machines: control nodes and managed hosts. Ansible is installed and controlled by a control node.
Managed hosts are displayed in an inventory, which also groups such systems for easy group administration. The inventory can be established in a static text file or calculated dynamically by programs that get data from various sources.
Ansible users write high-level plays to ensure that a host or collection of hosts is in a specific condition. A play executes a sequence of tasks on the hosts in the order indicated by the play. These plays are written in YAML and saved in a text file. A playbook is a file containing one or more plays.
Every task executes a module, which is a small code snippet (coded in Python, PowerShell, or another language) and comes with particular arguments.
when you use Ansible to do a task, it checks if things on your system are the way you want them to be. For example, it might make sure a file exists, or a specific system is set up. If things are not as they should be, Ansible fixes them. Ansible is smart; it won’t make unnecessary changes. If a task fails (something goes wrong), Ansible stops working on that task for the affected parts of your computer.
Ansible is designed to be safe to use multiple times. You can run it on your system over and over, and if everything is already how you want it, Ansible won’t make any changes. There are some special commands you can use, but you need to be careful with them to make sure they work safely and don’t cause problems.
Installed Ansible on a control node RHEL9
Register your system with the Red Hat Subscription Manager
sudo subscription-manager register
Attach your Red Hat Ansible Engine subscription. This command helps you find your Red Hat Ansible Engine subscription:
sudo subscription-manager list --available
sudo subscription-manager attach --pool=<engine-subscription-pool>
Checking the repo list for the latest Ansible platform
[admin@localhost ~]$ sudo subscription-manager repos --list | grep ansible
Repo ID: ansible-automation-platform-2.4-for-rhel-9-aarch64-source-rpms
Repo URL: https://cdn.redhat.com/content/dist/layered/rhel9/aarch64/ansible-automation-platform/2.4/source/SRPMS
Repo ID: ansible-automation-platform-2.4-for-rhel-9-aarch64-debug-rpms
Repo URL: https://cdn.redhat.com/content/dist/layered/rhel9/aarch64/ansible-automation-platform/2.4/debug
Repo ID: ansible-automation-platform-2.4-for-rhel-9-aarch64-rpms
Repo URL: https://cdn.redhat.com/content/dist/layered/rhel9/aarch64/ansible-automation-platform/2.4/os
Enable the Red Hat Ansible Engine repository.
[admin@localhost ~]$ sudo subscription-manager repos --enable ansible-automation-platform-2.4-for-rhel-9-aarch64-rpms
View Subscription Management repositories.
[admin@localhost ~]$ sudo dnf repolist
Install Ansible-core
[admin@localhost ~]$ sudo dnf install ansible-core
Verifying ansible version
[admin@localhost ~]$ ansible --version
ansible [core 2.15.6]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/admin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.9/site-packages/ansible
ansible collection location = /home/admin/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.9.18 (main, Sep 7 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
Managed Node
Ansible has the advantage of not requiring managed hosts to install a specific agent. To guarantee that the systems are in the specified condition, the Ansible control node connects to managed hosts over a standard network protocol.
Linux and UNIX-managed hosts need to have Python 2 (version 2.6 or later) or Python 3 (version 3.5 or later) installed for most modules to work.