LOGBOOK

HELP

Quiz Entry - updated: 2026.11.12

How do you combine several conditions with and and or in a when statement?

or is true if either side is true; and needs both sides true. Write them inside one expression.

Either RHEL or Fedora:

when: ansible_facts['distribution'] == "RedHat" or ansible_facts['distribution'] == "Fedora"

RHEL 9.0 and one specific kernel:

when: ansible_facts['distribution_version'] == "9.0" and ansible_facts['kernel'] == "5.14.0-70.13.1.el9_0.x86_64"

Think of or as widening the set of hosts that match and and as narrowing it. Mixing them without parentheses relies on precedence (and binds tighter than or, as in Python), which is easy to misread; group with parentheses as soon as both appear in one condition.

Go deeper:

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