Browse Ansible in a Minute A–Z
Every published guide, grouped by title. Use search on the guides home when you know the problem but not the name.
A
C
Ansible Core ·
Combine list and dictionary variables
Join two lists with + and merge two dictionaries with the combine filter.
AAP 2.7 ·
Create a job template in AAP 2.7
Create a job template in Red Hat Ansible Automation Platform (AAP) 2.7 to run a playbook from a project against an inventory.
Certified Collections ·
Create a Kubernetes namespace
Use kubernetes.core to create a Kubernetes namespace with a clear name.
AAP 2.7 ·
Create a survey on a job template in AAP 2.7
Add a survey question to a job template in AAP 2.7 so launch prompts the operator for input.
Certified Collections ·
Create an Azure resource group
Use azure.azcollection to create an Azure resource group in a chosen region.
Certified Collections ·
Create an EC2 instance with an encrypted EBS volume
Use amazon.aws to create an EC2 instance that attaches an encrypted EBS root volume.
AAP 2.7 ·
Create an inventory in AAP 2.7
Create an inventory in Ansible Automation Platform 2.7 so you can group hosts for jobs.
D
E
L
R
U
Ansible Core ·
Use a dictionary variable for key-value data
Define a YAML dictionary and read one value with bracket notation. Bracket notation always works.
Ansible Core ·
Use a list variable for multiple values
Define a YAML list variable and select an item by index. The first item is index 0.
AAP 2.7 ·
Use a survey to set extra variables in AAP 2.7
Use a job template survey in AAP 2.7 so launch answers become extra variables in the playbook.
Ansible Core ·
Use all and any to test list values
Use the all test when every list value must be true. Use the any test when at least one value must be true.
Ansible Core ·
Use any_errors_fatal to abort the play
Set any_errors_fatal so a failure on one host stops the play on every host.
Ansible Core ·
Use block rescue always to handle a failed task
Use block, rescue, and always to recover from a failed task and still run cleanup.
Ansible Core ·
Use break_when to stop a loop
Set loop_control break_when so Ansible exits the loop after the item that matches the condition.
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 changed_when to mark when a task changes the system
Use changed_when to report changed only when the task actually changed the system.
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 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 default to handle an undefined variable
Use the default filter so a task still runs when a variable is undefined.
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 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.
Ansible Core ·
Use dict2items to loop a dictionary
Pipe a dictionary through dict2items so loop can walk each key and value.
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 facts.d to add local facts
Place a .fact file in /etc/ansible/facts.d and read it as ansible_local after setup runs.
Ansible Core ·
Use failed_when to control when a task fails
Use failed_when to decide failure from the registered result instead of the default return code alone.
Ansible Core ·
Use gather_facts false to skip fact gathering
Set gather_facts false so Ansible does not run setup at the start of the play.
Ansible Core ·
Use human_readable to format a byte count
Pipe a byte count through human_readable so the message shows a size people can read, such as 10.00 KB.
Ansible Core ·
Use human_to_bytes to parse a size string
Pipe a size string through human_to_bytes so a task gets a raw byte integer such as 10240.
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 ignore_unreachable to continue after an unreachable host
Set ignore_unreachable so Ansible continues after a host cannot be contacted.
Ansible Core ·
Use index_var to track loop position
Set loop_control index_var so each iteration exposes a 0-based index you can print or pass to a task.
Ansible Core ·
Use list to loop over dictionary keys
Pipe dict.keys() through the list filter so a loop works on Python 3.
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 loop over inventory hosts
Use loop with groups['all'] or ansible_play_batch so one task iterates inventory hostnames.
Ansible Core ·
Use loop to run a task for each item in a list
Use loop to install each RHEL package name in a list with one package task.
Ansible Core ·
Use loop_control label to limit loop output
Set loop_control label so the console shows one field per item instead of the whole loop item.
Ansible Core ·
Use loop_control pause between loop items
Set loop_control pause so Ansible waits a number of seconds after each loop item before it starts the next one.
Ansible Core ·
Use merge_variables to combine matching variables
Use the community.general.merge_variables lookup to merge every variable whose name matches a prefix, suffix, or regular expression.
Ansible Core ·
Use notify and handlers to run a task after a change
Use notify with a handler so Ansible restarts a service only after a config file changes.
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 now to get the current time in a template
Use now() when you need the current time, not the time facts were gathered.
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 query to get lookup results as a list
Use query (or q) when a lookup must return a list you can loop over.
Ansible Core ·
Use register to capture task output
Use register to store a task result, then read fields such as stdout in a later task.
Ansible Core ·
Use run_once to run a task on a single host
Use run_once so Ansible prints a cluster-wide message once instead of on every host.
Ansible Core ·
Use search to match a pattern anywhere in a string
Use the Jinja search test in when to match a regex pattern anywhere in a string.
Ansible Core ·
Use serial to run a play against 20% of hosts at a time
Use the serial keyword to limit how many hosts Ansible processes in each batch.
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 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 truthy to test whether a value is true
Use the truthy test in when to treat a non-empty or true-like value as true.
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 until to retry a task until a condition is met
Use until with retries and delay to poll a task until a condition is true.
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 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 on include_tasks, not import_tasks
Put when on include_tasks so Ansible evaluates the condition once. import_tasks copies when onto every imported task.
Ansible Core ·
Use when to run a task only if a condition is true
Use when to skip a task unless a condition evaluates to true.
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 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 ·
Use when with loop to skip items
Combine when with loop so Ansible tests the condition for each item and skips the rest.