Ansible in a Minute · Ansible Core ·
Use truthy to test whether a value is true
Short answer
Use the truthy test in when to treat a non-empty or true-like value as true.
Subscribe for updates
Get an email whenever we publish new guides and blog posts. Unsubscribe anytime.
By subscribing you agree we may email you about Ansible in a Minute and related Level Up Labs updates. We store your address in the same lead sheet as our contact form.
Request
run debug when feature_flag is truthy
Example
A quick heads-up: Every environment is different. Review and test this example before you run it on systems you care about.
---
- name: Test whether feature_flag is truthy
hosts: all
gather_facts: false
vars:
feature_flag: "yes"
tasks:
- name: Print when feature flag is truthy
ansible.builtin.debug:
msg: Feature flag is truthy
when: feature_flag is truthyHow it works
truthy follows Python truth rules. A non-empty string is true. An empty string, 0, none, and an empty list are false. Use is falsy for the inverse.
When to use it
- Branching on extra vars that arrive as strings
- Skipping work when a flag is empty
Requirements
- Ansible: >=2.14
Validation
- Syntax validated
- Not execution-tested
- Last verified 2026-09-15
Notes
is truthy(convert_bool=True) converts strings such as yes, on, true, no, and off before the test. Without convert_bool, the string off is still truthy because it is not empty. Use Jinja test syntax (is truthy), not a filter.
Reference
- Testing truthiness (Ansible docs)
Built for every Ansible use case in every organization
BacklogZero can generate this kind of automation in your environment, just like it did here.