ansible.builtin.bool filter – cast into 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 even without specifying the collections: keyword. However, we recommend you use the FQCN 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 cast the input into a boolean (True or False) value.

Input

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

Parameter

Comments

Input

any / required

Data to cast.

Examples

# simply encrypt my key in a vault
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 resulting of casting the input expression into 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.