LOGBOOK

HELP

Quiz Entry - updated: 2026.11.12

How does the in operator let one condition check a host against a list of supported systems?

when: ansible_facts['distribution'] in supported_distros is true when the host's distribution fact appears as an element of the author's list.

- name: Demonstrate the "in" keyword
  hosts: all
  gather_facts: true
  vars:
    supported_distros:
      - RedHat
      - Fedora
  tasks:
    - name: Install httpd using dnf, where supported
      ansible.builtin.dnf:
        name: httpd
        state: present
      when: ansible_facts['distribution'] in supported_distros

Two different sources meet here. ansible_facts['distribution'] is a fact: Ansible discovers it on each managed host during the Gathering Facts step (so gather_facts must not be turned off). supported_distros is a variable the playbook author wrote. On a Fedora host the fact is "Fedora", which is in the list, so dnf runs; on an Ubuntu host it is "Ubuntu", so the task is skipped.

One list replaces a chain like distribution == "RedHat" or distribution == "Fedora", and supporting another system means adding one line to the list. The comparison is exact and case-sensitive: "redhat" would not match "RedHat".

Go deeper:

From Quiz: ITIA / Ansible Task Control: Loops, Conditionals, Handlers and Error Handling | Updated: Nov 12, 2026