Ansible is a powerful and widely adopted automation tool for SysAdmins, Developers, Network Engineers and many other users. When writing Ansible playbooks you may want to execute different tasks, or have different goals, depending on the value of a fact (data about the remote system), a variable, or the result of a previous task.
One of the condition is execution of a task if the OS family or OS Distribution is matched. This is usually achieved by using ansible_facts[‘os_family’] & ansible_facts[‘distribution’] fact. Ansible facts are variables containing information about the remote systems to be managed. With facts, you can use the behavior or state of one system as configuration on other systems.
In this guide we share a list of OS Family and OS distributions and how Ansible will group then.
Common Ansible OS Family & Distribution Facts
1. RedHat OS Family
Below is a list of OS distributions that fit into RedHat OS Family:
- RedHat
- CentOS
- Fedora
- Scientific
- CloudLinux
- OracleLinux
- Amazon
- XenServer
Usage examples:
# OS Family
when: ansible_facts['os_family'] == "RedHat" # CentOS 8, CentOS 7,Fedora 33, Amazon Linux 2, e.t.c
# Apply condition to a specific Distribution
when: ansible_facts['distribution'] == "CentOS" # CentOS 8,7,6
when: ansible_facts['distribution'] == "Amazon" # Amazon Linux
when: ansible_facts['distribution'] == "Fedora" # Fedora 33,32,31,..
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "8") # CentOS 8 only
2. Debian OS Family
Distributions:
- Debian
- Ubuntu
Usage examples:
# Apply to either
when: ansible_facts['os_family'] == "Debian" # Debian 10,9,..,Ubuntu 20.04,18.04,e.t.c
# Specific distribution examples:
when: ansible_facts['distribution'] == "Debian" # Debian 10,9,8,..
when: ansible_facts['distribution'] == "Ubuntu" # Ubuntu 20.04, 18.04, 16.04,..
when: (ansible_facts['distribution'] == "Debian" and ansible_facts['distribution_major_version'] == "10") # Only Debian 10
when: (ansible_facts['distribution'] == "Ubuntu" and ansible_facts['distribution_major_version'] == "20") # Only Ubuntu 20.04
3. Suse OS Family
- SUSE
- SLED – SUSE Linux Enterprise Desktop
- SLES – SUSE Linux Enterprise Server
when: ansible_facts['os_family'] == "Suse"
when: ansible_facts['distribution'] == "SLES"
4. Gentoo OS Family
- Gentoo
when: ansible_facts['os_family'] == "Gentoo"
when: ansible_facts['distribution'] == "Gentoo"
5. Archlinux OS Family
- Archlinux
when: ansible_facts['os_family'] == "Archlinux"
when: ansible_facts['distribution'] == "Archlinux"
6. Mandrake OS Family
- Mandriva
when: ansible_facts['os_family'] == "Mandrake"
when: ansible_facts['distribution'] == "Mandriva"
7. Solaris OS Family
- Solaris
- Nexenta
- OmniOS
- OpenIndiana
- SmartOS
when: ansible_facts['os_family'] == "Solaris"
when: ansible_facts['distribution'] == "OmniOS"
when: ansible_facts['distribution'] == "SmartOS"
8. AIX
when: ansible_facts['os_family'] == "AIX"
9. Alpine OS Family
- Alpine Linux
when: ansible_facts['os_family'] == "Alpine"
when: ansible_facts['distribution'] == "Alpine"
10. macOS – Darwin
when: ansible_facts['os_family'] == "Darwin"
11. FreeBSD
- FreeBSD
when: ansible_facts['os_family'] == "FreeBSD"
12. HP-UX
- HP-UX
when: ansible_facts['os_family'] == "HP-UX"
13. Windows
when: ansible_facts['os_family'] == "Windows"
Extra Distribution examples
- VMware ESXi
when: ansible_facts['distribution'] == "VMwareESX"
- OpenWrt
when: ansible_facts['distribution'] == "OpenWrt"
- CoreOS
when: ansible_facts['distribution'] == "Coreos"
- ALT Linux
when: ansible_facts['distribution'] == "Altlinux"
More guides on Ansible: