Install and Use Ansible on RHEL
Ansible turns repetitive RHEL administration into repeatable, auditable automation. A configuration management playbook can install packages, enforce service states, distribute files, and identify configuration drift across a fleet. YAML playbooks provide a readable form of infrastructure as code while giving administrators a consistent path from a blank server to a known baseline.
This guide demonstrates how to install and use Ansible for configuration management on RHEL 8 and 9. It assumes a licensed host with an administrative user, working sudo access, SSH connectivity, and the Python 3 runtime supplied by RHEL. The examples use private addresses and Australian host naming, but the workflow also suits hybrid estates connected to cloud platforms.
Install Ansible on RHEL
On a subscribed RHEL system, Ansible Core is available from the configured AppStream repositories. Register the system if necessary, then install the minimal controller package and Git:
sudo dnf install -y ansible-core git
ansible --version
The output should show the RHEL-packaged ansible-core build and a supported Python runtime. Avoid replacing it with an arbitrary pip installation, which can conflict with Red Hat package management. Ansible is agentless and normally communicates with managed hosts over SSH. Install additional collections, such as ansible.posix, only from an approved source and pin compatible versions for repeatable builds.
Prepare a clear inventory
An inventory maps logical groups to machines. Host names can come from DNS, or ansible_host can point directly to a private address. Group variables hold shared settings, while credentials should remain outside the inventory file.
[web]
rh-web-01.au.internal ansible_host=10.20.30.11
rh-web-02.au.internal ansible_host=10.20.30.12
[web:vars]
ansible_user=au_ops
ansible_python_interpreter=/usr/bin/python3
Run ansible-inventory --graph to confirm group membership, then test connectivity with ansible web -m ping. Inventory plugins can also retrieve cloud instances, which is useful when servers are created in the AWS Sydney region instead of being registered permanently by hand.
Build a first RHEL playbook
A playbook is a YAML document that declares the desired state of a managed host. This initial example installs and enables Apache HTTP Server:
---
- name: Configure RHEL web nodes
hosts: web
become: true
tasks:
- name: Install httpd
ansible.builtin.dnf:
name: httpd
state: present
- name: Start and enable httpd
ansible.builtin.service:
name: httpd
state: started
enabled: true
Validate the file with ansible-playbook --syntax-check, preview it using --check --diff, and then apply it normally. The dnf and service modules are idempotent: repeated runs should report ok instead of changing an already compliant server. Treat check mode as a review aid because some modules gather incomplete facts or cannot predict every possible change.
Manage services and configuration
Modules make playbooks declarative, while handlers restart a service only after relevant configuration changes. For example, a template task can render an NGINX virtual host under /etc/nginx/conf.d, notify a handler, and open the HTTP port with ansible.posix.firewalld. This reduces manual editing and prevents unnecessary service restarts.
Broader Apache and NGINX deployment guidance is available in the web server guides. This is particularly useful for Australian hosting providers, where NGINX is commonly used as a reverse proxy in front of Apache or application servers. Keep site content, TLS material, and application secrets in separate secured roles.
Test changes without disrupting production
Run every new playbook against a staging group before production. Check the diff, test service reloads, and use --limit to restrict a play. Capture output through AWX, Ansible Automation Platform, or simple CI logs, and schedule changes during an approved maintenance window. A local custom common to Australian operations is to align these windows with AEST or AEDT rather than relying blindly on UTC.
For isolated destructive tests, a chroot can provide a useful RHEL-compatible laboratory. The CentOS chroot setup demonstrates the directory layout and package tooling, although package versions should match the target RHEL release. Test user creation, firewall changes, and service removal before applying those operations to production hosts.
Secure and extend automation
Control access with individual SSH keys, passwordless sudo where policy allows, and a dedicated automation account. Store sensitive variables in Ansible Vault, protect the vault password outside the repository, and restrict permissions on inventories and playbooks. The become keyword elevates privileges only for designated tasks, making access easier to review.
Collections extend Ansible’s functionality, while roles package tasks, variables, handlers, and templates for reuse. A browser-based tool such as the Sakis3G server panel can complement command-line Ansible for teams wanting a visual administrative layer. Playbooks should nevertheless remain the authoritative, version-controlled definition of each system’s desired state.
Operate Ansible in Australian environments
Australian administrators often support servers across Sydney, Melbourne, and Brisbane, alongside workloads in AWS ap-southeast-2 and other regions. A practical operating model is to commit playbooks to Git, test them against a small staging inventory, require peer review, and promote the same artifact through production. Local managed-service providers and enterprise Red Hat support arrangements make this disciplined approach valuable in the Australian market, where audit evidence and change traceability matter.
Keep the desired state in version-controlled YAML, apply it through small idempotent playbooks, and review every diff before execution. That is the Ansible configuration management principle to remember: repeatable automation leaves RHEL servers consistent and every change explainable.