Ansible Core
Browse A–ZAtomic lessons on Ansible language, playbooks, inventory, and engine.
Highlighted guide
More in this track
Ansible Core ·
Use dict2items to loop a dictionary
Pipe a dictionary through dict2items so loop can walk each key and value.
Ansible Core ·
Use variables in handler parameters
Put the service name in the handler module arguments. Do not put a variable in the handler name.
Ansible Core ·
Use when with a variable and the bool filter
Apply the bool filter when a string variable such as yes must be treated as true in when.
Ansible Core ·
Use changed_when so a task can notify a handler
Handlers run only when a task reports changed. Use changed_when to control whether notify fires.
Ansible Core ·
Use contains to test if a list has a value
Use the contains test with selectattr to find a list item whose field includes a value.
Ansible Core ·
Use ignore_errors to continue after a failed command
Set ignore_errors so Ansible continues the play on a host after a task returns failed.
Ansible Core ·
Use query in loop instead of lookup
Use query with loop so lookup plugin results are a list. lookup returns a comma-joined string by default.
Ansible Core ·
Use ternary to choose a value for true or false
Use the ternary filter to return one value when a test is true and another when it is false.
Ansible Core ·
Use default omit to skip an optional module argument
Use default(omit) so Ansible omits a module argument when the variable is undefined instead of sending a value.
Ansible Core ·
Use delegate_facts to assign facts to the delegated host
Use delegate_facts true so facts gathered with delegate_to are stored on the delegated host, not the play host.
Ansible Core ·
Use environment to set remote environment variables
Use the environment keyword on a task so the remote action runs with specific environment variables.
Ansible Core ·
Use loop over a list of hashes
Use loop with a list of dictionaries and reference item keys such as item.name in the task.
Ansible Core ·
Use notify in a loop to target dynamic handlers
Use notify with item in a loop so each changed template can notify a matching handler name.
Ansible Core ·
Use shell or true to accept a non-zero exit
Append || /bin/true to a shell command when a non-zero exit code should still count as success.
Ansible Core ·
Use undef to clear a variable for a block
Use undef() to undefine a variable of lesser precedence so a block must supply its own value.
Ansible Core ·
Use version to compare version numbers
Use the version test in when to compare version strings with operators such as greater-than.
Ansible Core ·
Use when with ansible_facts to skip a task by OS
Use when with ansible_facts so a task runs only on hosts that match an OS family or distribution.
Ansible Core ·
Debug a when condition before you skip a task
Print the values in a when expression so you can see why Ansible skips a task.
Ansible Core ·
Use default to handle an undefined variable
Use the default filter so a task still runs when a variable is undefined.
Ansible Core ·
Use delegate_to to run a task on another host
Use delegate_to so a task runs on localhost (or another host) while the play still targets the current inventory host.