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
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
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 examplevar=FALSE
would create a string equal toFALSE
.
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).
--extra_vars
CLI parameterAll variables passed as extra-vars in CLI are of string type.