Ansible in a Minute
Learn one useful Ansible thing at a time, quickly.
A growing library of small, practical Ansible lessons. Each guide teaches one key concept, operator task, or Certified Collection use case.
Tracks
Browse A–ZRecent guides
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 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 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 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 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 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 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 ·
Combine list and dictionary variables
Join two lists with + and merge two dictionaries with the combine filter.
Ansible Core ·
Load custom facts then use them in when
Set a custom fact first, then use that value in when so later tasks can skip or run.
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 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 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 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 ignore_unreachable to continue after an unreachable host
Set ignore_unreachable so Ansible continues after a host cannot be contacted.
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.
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 when with loop to skip items
Combine when with loop so Ansible tests the condition for each item and skips the rest.
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.
Subscribe for updates
Get an email whenever we publish new guides and blog posts. Unsubscribe anytime.
By subscribing you agree we may email you about Ansible in a Minute and related Level Up Labs updates. We store your address in the same lead sheet as our contact form.