Ansible_os_family question


We are working on moving from CentOS to Rocky, changing bits and pieces of our Ansible setup. I ran into a problem yesterday when using a conditional and ansible_os_family.

We use:

when: ansible_os_family == “RedHat”

for our Red Hat based systems and when I ran that against a test Rocky system, it was skipped. Looking into it, the fact that ansible pulled is “ansible_os_family”: “Rocky”.

So my question, should “ansible_os_family” be RedHat instead of Rocky as CentOS is? Is that a bug, or by design?

ansible -m ansible.builtin.setup | grep -i os_family
        "ansible_os_family": "Rocky",

ansible -m ansible.builtin.setup | grep -i redhat
        "ansible_distribution_file_path": "/etc/redhat-release",
        "ansible_distribution_file_variety": "RedHat",

Thank you


Support for Rocky has been added to Ansible 2.11, but unfortunately we couldn’t get this backported to the Ansible version available through EPEL.

I’m not sure what solution others have found, but I’ve installed the latest stable version from pip into a virtualenv.

Edit: You’ll need to create this virtualenv with --system-site-packages so it picks up the python3-dnf package.

I think I may have presented my question wrong.

Rocky is currently showing up as “ansible_os_family”: “Rocky”, instead of “ansible_os_family”:“RedHat” like CentOS does. Is that intended?

That’s not intended, no. Your Ansible installation is falling-back to that value since it does not include the patches which lets it know Rocky is a RHEL-like system.

Oh that makes sense, thank you for the clarification!

1 Like


It took me a little while to figure it out, so for someone else here is the basic setup:

Set up virtualenv:

virtualenv --system-site-packages myansible

Activating virtualenv

source myansible/bin/activate

Installing ansible 2.11

pip install ansible-core

Run your role/playbook

Remember to add modules/collections required in your play

Even after setting the above steps, we could see the os_family still not shows as “Rocky”. Used ansible 2.11.4.

Anyone else faced this issue

Hi, you’ve got it the other way around?

I’ll try to summarize the state of affairs

  ansible_os_family: RedHat  # -> this is correct
  ansible_os_family: Rocky  # -> this is incorrect
  ansible_os_family: Rocky  # -> this is incorrect

ansible 2.9 is very old and at the time Rocky Linux was finished there was already a feature freeze in place, that’s why it will not be fixed. To mitigate the issue at least a little bit the ansible 2.9 in EPEL was patched, so that it shows ‘RedHat’.

That means, if you are using ansible 2.9 but not the version from EPEL you might want to change your conditions from

when: ansible_os_family == 'RedHat'
when: ansible_os_family in ['RedHat', 'Rocky']

P.S.: in my original post I got it wrong for ansible 2.10, 2.10 is also not fixed! I corrected this in the table above.

That’s makes sense. Thank you for the clarification :+1:

We must define hostanme manually for the moment on ansible 2.9.21 :slight_smile:

TASK [common : Define Hostname] **********************************************************************************************************************************************************************************
fatal: [192.168.X.X]: FAILED! => {“changed”: false, “msg”: “hostname module cannot be used on platform Linux (Rocky)”}

According to ansible-doc hostname the module hostname has option use to set the update strategy if the autodetect fails.


when: "ansible_distribution" == "Rocky"
when: "ansible_distribution" == "CentOS"

Together with OS Major Version

when: "ansible_distribution_major_version" == "8"