How to Patch Red Hat Systems in Ansible Correctly
Abotts Logo Abotts Partners with singapore based tech giant to help migrate their public sector customer from Sybase to SQL server.
Upworks Logo Abotts partners with NYPL to integrate with their partner libraries.
Abotts Logo ABOTTS partners with County in Los Angeles to upgrade their court infrastructure into new technologies.
Upworks Logo Upworks Inc partners with ABOTTS to build their Oracle Cloud Infrastructure (OCI) and migrate their custom applications to OCI.
Abotts partners with startup to manage and maintain their IT infrastructure and support SOC2 reporting.
Gnorth Logo Abotts Inc Partners with Gnorth consulting to deploy exadata and ODA for a large public sector customer.
Abotts Logo Abotts Partners with singapore based tech giant to help migrate their public sector customer from Sybase to SQL server.
Upworks Logo Abotts partners with NYPL to integrate with their partner libraries.
Abotts Logo ABOTTS partners with County in Los Angeles to upgrade their court infrastructure into new technologies.
Upworks Logo Upworks Inc partners with ABOTTS to build their Oracle Cloud Infrastructure (OCI) and migrate their custom applications to OCI.
Abotts partners with startup to manage and maintain their IT infrastructure and support SOC2 reporting.
Gnorth Logo Abotts Inc Partners with Gnorth consulting to deploy exadata and ODA for a large public sector customer.

How to Fix OS Patching Condition in Ansible for Red Hat Family

When working with Ansible playbooks for OS patching across multiple Linux distributions, it’s important to use the correct conditional checks for the operating system family.
A common mistake occurs when using an incorrect ansible_os_family value, which causes Ansible tasks to skip or fail to patch the intended hosts.

The Problem

You may have an Ansible playbook that uses a conditional like this:

However, when you try to patch a Red Hat–based OS (e.g., RHEL, CentOS, Rocky Linux, AlmaLinux), the task does not execute, even though the system is part of the Red Hat family.

The issue is that the condition is checking for “amazonlinux” instead of the correct OS family name.

Understanding ansible_os_family

Ansible automatically gathers system facts such as:

  • ansible_distribution
  • ansible_distribution_version
  • ansible_os_family

The ansible_os_family fact helps you group related Linux distributions together.
For example:

 Correct Way to Handle Red Hat Family OS Patching

Instead of checking for a specific flavor like “amazonlinux”, use the OS family condition.

Correct Playbook Example:

This condition ensures the patching task runs on:

  • Red Hat Enterprise Linux (RHEL)
  • CentOS
  • Rocky Linux
  • AlmaLinux
  • Amazon Linux

Example Final Playbook

This playbook ensures all Red Hat family systems are properly updated during patching, regardless of the specific distribution flavor.

Key Takeaways

  • ansible_os_family groups distributions by their lineage (e.g., RedHat, Debian).
  • ansible_distribution gives the exact OS name (e.g., Amazon, CentOS, Ubuntu).
  • Use ansible_os_family == “RedHat” for broader patching across Red Hat–based systems.
  • Use ansible_distribution == “Amazon” or others only for targeted automation.

Reference Documentation