Quiz Entry - updated: 2026.11.12
What are conditionals for in Ansible, and what kinds of values can a condition test?
They let a task (or play) run only when a condition holds, so one playbook can treat hosts differently; conditions can test playbook variables, registered variables and facts.
A playbook usually targets many hosts that are not identical. Conditionals let one playbook adapt instead of needing a copy per host type. Typical uses:
- compare a hard limit in a variable (for example
min_memory) with the memory a host actually has before installing a service; - check the captured output of a command and skip follow-up work if it failed;
- read network facts to decide which configuration template to send (bonding or trunking);
- read the CPU count to tune a web server;
- compare a registered checksum of a config file with a known value to see whether the service was changed.
Operators exist for strings, numbers and booleans, so the same when mechanism covers all of these.
Go deeper:
Conditionals (official docs) โ conditions on facts, registered variables and variables.