- 
                Notifications
    
You must be signed in to change notification settings  - Fork 741
 
Extend boolean values section in playbooks_variables #1285
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
base: devel
Are you sure you want to change the base?
Changes from all commits
06b1850
              6c41ec7
              9578876
              1262ca5
              4e4d688
              04f8f13
              7fc8f42
              cc8b337
              6bf26d7
              0b03d2d
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -101,19 +101,76 @@ 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: | ||
| Documentation examples focus on ``true/false`` to be compatible with ``ansible-lint`` default settings. However, you can use any of the following values: | ||
| 
     | 
||
| Native boolean | ||
| -------------- | ||
| 
     | 
||
| Ansible treats these values as native booleans: | ||
| 
     | 
||
| .. table:: | ||
| :class: documentation-table | ||
| 
     | 
||
| =============================================================================================== ==================================================================== | ||
| Valid values Description | ||
| =============================================================================================== ==================================================================== | ||
| ``True`` , ``'true'`` , ``'t'`` , ``'yes'`` , ``'y'`` , ``'on'`` , ``'1'`` , ``1`` , ``1.0`` Truthy values | ||
| ================= ================= | ||
| Valid values Description | ||
| ================= ================= | ||
| ``true`` Truthy values | ||
| 
     | 
||
| ``false`` Falsy values | ||
| 
     | 
||
| ================= ================= | ||
| 
     | 
||
| Implicit boolean | ||
| ---------------- | ||
| 
     | 
||
| Ansible recognizes these values as booleans: | ||
| 
     | 
||
| .. table:: | ||
| :class: documentation-table | ||
| 
     | 
||
| ================================================================================= ==================================================================== | ||
| Valid values Description | ||
| ================================================================================= ==================================================================== | ||
| ``yes`` , ``Yes`` , ``YES`` , ``True`` , ``TRUE`` , ``on`` , ``On`` , ``ON`` Truthy values | ||
| 
     | 
||
| ``no`` , ``No`` , ``NO`` , ``False`` , ``FALSE`` , ``off`` , ``Off`` , ``OFF`` Falsy values | ||
| 
     | 
||
| ================================================================================= ==================================================================== | ||
| 
     | 
||
| Interpretable as boolean | ||
| ------------------------ | ||
| 
     | 
||
| ``False`` , ``'false'`` , ``'f'`` , ``'no'`` , ``'n'`` , ``'off'`` , ``'0'`` , ``0`` , ``0.0`` Falsy values | ||
| You need to use the ``| bool`` filter to interpret these strings values as native booleans in logical expressions. Boolean expressions also work with these values without a filter, but Ansible interprets them in Python style. | ||
| 
     | 
||
| =============================================================================================== ==================================================================== | ||
| .. table:: | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Falseso it realy only converts 'matching  There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'`` , ``'t'`` , ``'yes'`` , ``'y'`` , ``'on'`` , ``'1'`` , ``1`` Truthy values | ||
| 
     | 
||
| ``'false'`` , ``'f'`` , ``'no'`` , ``'n'`` , ``'off'`` , ``'0'`` , ``0`` Falsy values | ||
| 
     | 
||
| ================================================================================= ==================================================================== | ||
| 
     | 
||
                
      
                  oraNod marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| For example, using ``'false'`` as a condition to run tasks: | ||
| 
     | 
||
| .. code-block:: yaml | ||
| 
     | 
||
| - hosts: web_servers | ||
| vars: | ||
| condition_var: 'false' | ||
| tasks: | ||
| - name: This task will run | ||
| debug: | ||
| msg: "{{ condition_var }}" | ||
| when: condition_var | ||
| 
     | 
||
| - name: This task will be skipped | ||
| debug: | ||
| msg: "{{ condition_var }}" | ||
| when: condition_var | bool | ||
| 
     | 
||
| .. _list_variables: | ||
| 
     | 
||
| 
          
            
          
           | 
    ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not really 'ansible native' but YAML that uses
trueandfalseand the rest of the list below, it would be 'more true' thatTrueandFalseare the 'native' options as Ansible evaluation happens inside Python and those are the 'Python native booleans', this also depends on context as inside a{{ }}expression it is Jinja doing the evaluation, which is again using Python under the hood.