How Exactly Does Ansible Parse Boolean Variables?

后端 未结 1 973
别跟我提以往
别跟我提以往 2020-12-14 07:28

In Ansible, there are several places where variables can be defined: in the inventory, in a playbook, in variable files, etc. Can anyone explain the following observations t

相关标签:
1条回答
  • 2020-12-14 07:58

    Variables defined in YAML files (playbooks, vars_files, YAML-format inventories)


    YAML principles

    Playbooks, vars_files, and inventory files written in YAML are processed by a YAML parser first. It allows several aliases for values which will be stored as Boolean type: yes/no, true/false, on/off, defined in several cases: true/True/TRUE (thus they are not truly case-insensitive).

    YAML definition specifies possible values as:

    y|Y|yes|Yes|YES|n|N|no|No|NO
    |true|True|TRUE|false|False|FALSE
    |on|On|ON|off|Off|OFF
    

    Ansible docs confirm that:

    You can also specify a boolean value (true/false) in several forms:

    create_key: yes
    needs_agent: no
    knows_oop: True
    likes_emacs: TRUE
    uses_cvs: false
    


    Variables defined in INI-format inventory files


    Python principles

    When Ansible reads an INI-format inventory, it processes the variables using Python built-in types:

    Values passed in using the key=value syntax are interpreted as Python literal structure (strings, numbers, tuples, lists, dicts, booleans, None), alternatively as string. For example var=FALSE would create a string equal to FALSE.

    If the value specified matches string True or False (starting with a capital letter) the type is set to Boolean, otherwise it is treated as string (unless it matches another type).



    Variables defined through --extra_vars CLI parameter


    All strings

    All variables passed as extra-vars in CLI are of string type.

    0 讨论(0)
提交回复
热议问题