ansible.vars package

class ansible.vars.AnsibleInventoryVarsData(*args, **kwargs)[source]

Bases: dict

ansible.vars.preprocess_vars(a)[source]

Ensures that vars contained in the parameter passed in are returned as a list of dictionaries, to ensure for instance that vars loaded from a file conform to an expected state.

ansible.vars.strip_internal_keys(dirty)[source]

All keys stating with _ansible_ are internal, so create a copy of the ‘dirty’ dict and remove them from the clean one before returning it

class ansible.vars.VariableManager[source]

Bases: object

extra_vars

ensures a clean copy of the extra_vars are made

set_inventory(inventory)[source]
options_vars

ensures a clean copy of the options_vars are made

get_vars(loader, play=None, host=None, task=None, include_hostvars=True, include_delegate_to=True, use_cache=True)[source]

Returns the variables, with optional “context” given via the parameter for the play, host, and task.

The context can possibly result in different sets of variables being returned due to the additional context.

The order of precedence is:

  • play->roles->get_default_vars (if there is a play context)
  • group_vars_files[host] (if there is a host context)
  • host_vars_files[host] (if there is a host context)
  • host->get_vars (if there is a host context)
  • fact_cache[host] (if there is a host context)
  • play vars (if there is a play context)
  • play vars_files (if there’s no host context, ignore file names that cannot be templated)
  • task->get_vars (if there is a task context)
  • vars_cache[host] (if there is a host context)
  • extra vars
invalidate_hostvars_cache(play)[source]
add_host_vars_file(path, loader)[source]

Loads and caches a host_vars file in the _host_vars_files dict, where the key to that dictionary is the basename of the file, minus the extension, for matching against a given inventory host name

add_group_vars_file(path, loader)[source]

Loads and caches a host_vars file in the _host_vars_files dict, where the key to that dictionary is the basename of the file, minus the extension, for matching against a given inventory host name

clear_facts(hostname)[source]

Clears the facts for a host

set_host_facts(host, facts)[source]

Sets or updates the given facts for a host in the fact cache.

set_nonpersistent_facts(host, facts)[source]

Sets or updates the given facts for a host in the fact cache.

set_host_variable(host, varname, value)[source]

Sets a value in the vars_cache for a host.

Submodules

ansible.vars.hostvars module

class ansible.vars.hostvars.HostVars(inventory, variable_manager, loader)[source]

Bases: _abcoll.Mapping

A special view of vars_cache that adds values from the inventory when needed.

set_variable_manager(variable_manager)[source]
set_inventory(inventory)[source]
set_host_variable(host, varname, value)[source]
set_nonpersistent_facts(host, facts)[source]
set_host_facts(host, facts)[source]

ansible.vars.unsafe_proxy module

class ansible.vars.unsafe_proxy.AnsibleUnsafe[source]

Bases: object

class ansible.vars.unsafe_proxy.UnsafeProxy[source]

Bases: object

class ansible.vars.unsafe_proxy.AnsibleJSONUnsafeEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]

Bases: json.encoder.JSONEncoder

encode(obj)[source]
class ansible.vars.unsafe_proxy.AnsibleJSONUnsafeDecoder(encoding=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None)[source]

Bases: json.decoder.JSONDecoder

decode(obj)[source]
ansible.vars.unsafe_proxy.wrap_var(v)[source]