Ansible Task Looping Directives: Difference between revisions
Jump to navigation
Jump to search
(Created page with "=Internal= * Ansible Concepts =Overview= =Looping Directives= ==<tt>with_items</tt>== An iterator whose elements can be accessed with <...") |
(→loop) |
||
Line 18: | Line 18: | ||
loop: "{{ jdks }}" | loop: "{{ jdks }}" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
An existing variable's field that reference a list can be used: | |||
<syntaxhighlight lang='yaml'> | |||
- name: Debug | |||
debug: | |||
var: item.path | |||
loop: "{{ some_task_result.files }}" | |||
</syntaxhighlight> | |||
==<tt>loop_control</tt>== | ==<tt>loop_control</tt>== | ||
==<tt>with_<lookup_plugin></tt>== | ==<tt>with_<lookup_plugin></tt>== | ||
The same as <code>[[#loop|loop]]</code> but adds the output of any lookup plugin to generate the item list. | The same as <code>[[#loop|loop]]</code> but adds the output of any lookup plugin to generate the item list. |
Revision as of 09:52, 4 July 2021
Internal
Overview
Looping Directives
with_items
An iterator whose elements can be accessed with item.<element>
.
loop
Takes a list for the task to iterate over, saving each list element into the item
variable (configurable via loop_control
)
jdks:
- corretto8
- corretto11
...
- name: Multiple items in a loop
homebrew_cask:
name: "{{ item }}"
state: present
loop: "{{ jdks }}"
An existing variable's field that reference a list can be used:
- name: Debug
debug:
var: item.path
loop: "{{ some_task_result.files }}"
loop_control
with_<lookup_plugin>
The same as loop
but adds the output of any lookup plugin to generate the item list.