LOGBOOK

HELP

Quiz Entry - updated: 2026.11.12

Why can when: run_my_task behave wrongly if run_my_task was set as "false" in quotes, and how do you guard against it?

Quoted, "false" is a non-empty string, not a boolean; older ansible-core treats it as true and runs the task, newer releases reject it. when: run_my_task | bool converts it properly.

Three ways to write the variable: quoted false is a string, unquoted false is a boolean, and the bool filter turns either into a real boolean

* Quoting turns the word false into a string; the bool filter turns it back. *

YAML decides the type when the file is parsed:

  • run_my_task: false is the boolean false, so the task is skipped.
  • run_my_task: "false" is the string "false", five characters long.

From ansible-core 2.12 up to 2.18, a non-empty string in when counts as true, so the quoted version runs the task, which is almost certainly not what the author meant. Since ansible-core 2.19, a conditional whose result is not a boolean is an error by default ("Conditionals must have a boolean result"), so the mistake now stops the play instead of passing silently.

The guard is the same in both cases. The bool filter turns known truthy and falsy strings ("false", "no", "0", "yes", ...) into real booleans and passes real booleans through unchanged:

when: run_my_task | bool

This matters most for values that arrive as strings, such as extra variables given on the command line with -e.

Go deeper:

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