when condition
A task keyword holding an expression; the task runs on a host only if the expression is true there, and is reported as skipped otherwise.
In more detail
It is written as a bare Jinja expression without double curly braces, as in when: ansible_facts.os_family == 'Debian'. It can compare variables, test facts or check registered results, and can be put on a whole block. Mind the types: a text value such as "false" is not the same as the Boolean false.
Related terms
- skipped — The task result meaning the task was deliberately not run on that host, usually because its when condition was false.
- fact — A variable Ansible discovers about a host itself, such as its operating system, host name, memory or network addresses.
- Jinja — A templating language for Python tools that fills placeholders in text, written inside double curly braces, with values and simple logic.
- Boolean — A value that can only be true or false.
- register — The task keyword that saves a task's result in a named variable so later tasks can read it.
Taught in
- Handlers And Notify — Ansible Configuration Management at Scale
- Gathering Facts — Ansible Configuration Management at Scale
- Conditionals — Ansible Configuration Management at Scale
- Loops — Ansible Configuration Management at Scale
- Conditionals: register, when, changed_when And failed_when — RHCE in Ansible (EX294): Automate Red Hat Systems
- Services And Boot Targets: Started Is Not Enabled — RHCE in Ansible (EX294): Automate Red Hat Systems
- Storage: Partitions, Volume Groups And Volumes Where The Disk Exists — RHCE in Ansible (EX294): Automate Red Hat Systems
- SELinux: Labels, Ports And Booleans That Persist — RHCE in Ansible (EX294): Automate Red Hat Systems
- Drill: Storage Only Where The Disk Exists — RHCE in Ansible (EX294): Automate Red Hat Systems