Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend boolean values section in playbooks_variables #1285

Open
wants to merge 10 commits into
base: devel
Choose a base branch
from
28 changes: 25 additions & 3 deletions docs/docsite/rst/playbook_guide/playbooks_variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,39 @@ Boolean variables
=================

Ansible accepts a broad range of values for boolean variables: ``true/false``, ``1/0``, ``yes/no``, ``True/False`` and so on. The matching of valid strings is case insensitive.
While documentation examples focus on ``true/false`` to be compatible with ``ansible-lint`` default settings, you can use any of the following:
While documentation examples focus on ``true/false`` to be compatible with ``ansible-lint`` default settings. You can use any of the following values:
skilyazhnev marked this conversation as resolved.
Show resolved Hide resolved

Native Boolean
oraNod marked this conversation as resolved.
Show resolved Hide resolved
skilyazhnev marked this conversation as resolved.
Show resolved Hide resolved
--------------

Values natively recognized as boolean by Ansible

.. table::
:class: documentation-table

=============================================================================================== ====================================================================
Valid values Description
=============================================================================================== ====================================================================
``True`` , ``TRUE`` , ``yes`` , ``true`` , ``True`` , ``on`` Truthy values

``False`` , ``false`` , ``FALSE`` , ``no``, ``off`` Falsy values

=============================================================================================== ====================================================================

Interpretable as Boolean
skilyazhnev marked this conversation as resolved.
Show resolved Hide resolved
------------------------

We need to use the filter ``| bool`` to interpret these strings values as native booleans in logical expressions. Boolean expressions will also work with these values without filter, but interpret them in python style.

.. table::
Copy link
Member

@bcoca bcoca Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bool filter, while is it Jinja, it is an Ansible customization which approximates (but does not really match) the YAML booleans, the table below is incorrect as this is the actual code:

    if a is None or isinstance(a, bool):
        return a
    if isinstance(a, string_types):
        a = a.lower()
    if a in ('yes', 'on', '1', 'true', 1):
        return True
    return False

so it realy only converts 'matching True' and everything else is False

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though this is something I'm planning to fix so they are closer to YAML by default but can be 'pythonic' otherwise.

:class: documentation-table

=============================================================================================== ====================================================================
Valid values Description
=============================================================================================== ====================================================================
``True`` , ``'true'`` , ``'t'`` , ``'yes'`` , ``'y'`` , ``'on'`` , ``'1'`` , ``1`` , ``1.0`` Truthy values
``'true'`` , ``'t'`` , ``'yes'`` , ``'y'`` , ``'on'`` , ``'1'`` , ``1`` , ``1.0`` Truthy values

``False`` , ``'false'`` , ``'f'`` , ``'no'`` , ``'n'`` , ``'off'`` , ``'0'`` , ``0`` , ``0.0`` Falsy values
``'false'`` , ``'f'`` , ``'no'`` , ``'n'`` , ``'off'`` , ``'0'`` , ``0`` , ``0.0`` Falsy values
skilyazhnev marked this conversation as resolved.
Show resolved Hide resolved

=============================================================================================== ====================================================================

oraNod marked this conversation as resolved.
Show resolved Hide resolved
Expand Down