How to Install and Configure Ansible on CentOS 9 Stream
Introduce
The configuration management system is designed to help administrators and operations teams easily control large numbers of servers. They allow you to control many different systems automatically from one central location. While there are many popular configuration management systems for Linux systems, such as Chef and Puppet, these systems are often much more complex than many people want or need. Ansible is a great alternative to these options because it has a much smaller initial cost to get started.
Ansible works by configuring the client from a computer that has Ansible components installed and configured. It communicates over regular SSH channels to get information from remote machines, issue commands, and copy files. Therefore, the Ansible system does not require the installation of any additional software on the client. This is one way Ansible simplifies server administration. Any server with an exposed SSH port can be placed under Ansible configuration management, regardless of what stage it is in its lifecycle.
Ansible adopts a modular approach, making it easy to extend the use of core system functions to address specific situations. Modules can be written in any language and communicate using standard JSON. Configuration files are primarily written in the YAML data serialization format due to its expressive nature and similarity to popular markup languages. Ansible can interact with clients through command line tools or through configuration scripts called Playbooks.
In this tutorial, you will install Ansible on a CentOS 9 Stream server and learn some basics about using the software.
Install Ansible
To start exploring Ansible as a means of managing different servers, we need to install the Ansible software on at least one machine.
To get Ansible for CentOS 9 Stream, first make sure that the CentOS 9 Stream EPEL repository is installed:
dnf install epel-release
Once the repository is installed, install Ansible with yum:
dnf -y install ansible-core
Verify installation.
ansible --version
We now have all the software needed to manage our servers through Ansible.
Configure the Ansible server
Ansible keeps track of all the servers it knows about through a “hosts” file. We need to set up this file before we can start communicating with our other computers.
Open the file as root like this:
vi /etc/ansible/hosts
You will see a file with lots of commented example configurations. Keep these examples in the file to help you learn Ansible’s configuration if you want to deploy more complex scenarios in the future.
The hosts file is quite flexible and can be configured in a number of different ways. The syntax we will use looks like this: