
Use bracket notation if you use keys which start and end with two underscores (which are reserved for special meanings in python) or are any of the known public attributes:Īdd, append, as_integer_ratio, bit_length, capitalize, center, clear, conjugate, copy, count, decode, denominator, difference, difference_update, discard, encode, endswith, expandtabs, extend, find, format, fromhex, fromkeys, get, has_key, hex, imag, index, insert, intersection, intersection_update, isalnum, isalpha, isdecimal, isdigit, isdisjoint, is_integer, islower, isnumeric, isspace, issubset, issuperset, istitle, isupper, items, iteritems, iterkeys, itervalues, join, keys, ljust, lower, lstrip, numerator, partition, pop, popitem, real, remove, replace, reverse, rfind, rindex, rjust, rpartition, rsplit, rstrip, setdefault, sort, split, splitlines, startswith, strip, swapcase, symmetric_difference, symmetric_difference_update, title, translate, union, update, upper, values, viewitems, viewkeys, viewvalues, zfill. Dot notation can cause problems because some keys collide with attributes and methods of python dictionaries. Once you understand the concepts and examples on this page, read about Ansible facts, which are variables you retrieve from remote systems.īoth of these examples reference the same value (“one”). The ansible-examples github repository contains many examples of using variables in Ansible. You can also create variables during a playbook run by registering the return value or values of a task as a new variable.Īfter you create variables, either by defining them in a file, passing them at the command line, or registering the return value or values of a task as a new variable, you can use those variables in module arguments, in conditional “when” statements, in templates, and in loops. You can define these variables in your playbooks, in your inventory, in re-usable files or roles, or at the command line. To represent the variations among those different systems, you can create variables with standard YAML syntax, including lists and dictionaries. With Ansible, you can execute tasks and playbooks on multiple different systems with a single command. Controlling how Ansible behaves: precedence rulesĪnsible uses variables to manage differences between systems.Virtualization and Containerization Guides.Controlling playbook execution: strategies and more.Executing playbooks for troubleshooting.Validating tasks: check mode and diff mode.Discovering variables: facts and magic variables.Variable precedence: Where should I put a variable?.Transforming variables with Jinja2 filters.When to quote variables (a YAML gotcha).Working with language-specific version managers.Controlling where tasks run: delegation and local actions.Understanding privilege escalation: become.
