ansible.builtin.bool filter – coerce some well-known truthy/falsy values to a boolean

Note

This filter plugin is part of ansible-core and included in all Ansible installations. In most cases, you can use the short plugin name bool. However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.bool for easy linking to the plugin documentation and to avoid conflicting with other collections that may have the same filter plugin name.

Synopsis

  • Attempt to convert the input value into a boolean (True or False) from a common set of well-known values.

  • Valid true values are (True, ‘yes’, ‘on’, ‘1’, ‘true’, 1).

  • Valid false values are (False, ‘no’, ‘off’, ‘0’, ‘false’, 0).

  • A deprecation warning will result if an invalid value is supplied.

  • For more permissive boolean conversion, consider the ansible.builtin.truthy or ansible.builtin.falsy tests.

  • String comparisons are case-insensitive.

Aliases: formerly_core_filter, formerly_core_masked_filter

Input

This describes the input of the filter, the value before | ansible.builtin.bool.

Parameter

Comments

Input

any / required

Data to convert.

Examples

# in vars
vars:
  isbool: "{{ (a == b) | bool }} "
  otherbool: "{{ anothervar | bool }} "

# in a task
...
when: some_string_value | bool

Return Value

Key

Description

Return value

boolean

The boolean result of coercing the input expression to a True or False value.

Returned: success

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.