Idempotent RHEL management with Ansible
Author: DEWOLF.IT
Use predictable inventories, roles, validation and repeat runs to operate RHEL with Ansible.
This English edition covers the main steps. See the Dutch article for the full detail and examples.
Make inventory predictable
Group hosts by a meaningful function and separate test and production inventory. Use group variables for shared settings and record any deliberate per-host differences. Keep secrets in an approved secret store.
# inventories/test/hosts.yml
all:
children:
rhel_web:
hosts:
web01.example.net:
web02.example.net:
vars:
ansible_user: automation
Give each role a clear contract
State which RHEL releases, inputs and privileges the role expects. Use purpose-built modules for packages, configuration and systemd. Notify handlers on changes so reloads occur only when needed. Validate configuration before a reload, and use a staged rollout for services that affect access.
- name: Install the web server
ansible.builtin.dnf:
name: httpd
state: present
- name: Install a validated SSH configuration
ansible.builtin.template:
src: sshd_config.j2
dest: /etc/ssh/sshd_config
owner: root
group: root
mode: '0600'
backup: true
validate: '/usr/sbin/sshd -t -f %s'
Prove repeatability and operation
Use check mode and diff where the modules support them. Run against a test host, verify the service as a consumer, and run it a second time to confirm the same state produces no unintended changes. Make failures stop dependent work and keep enough evidence to identify the host and task.
Check the version-specific Ansible documentation.
