Ansible Task Looping Directives: Difference between revisions
Jump to navigation
Jump to search
(→loop) |
|||
Line 29: | Line 29: | ||
msg: "{{ item }}" | msg: "{{ item }}" | ||
with_items: "{{ find_result.files | json_query('[*].path') }}" | with_items: "{{ find_result.files | json_query('[*].path') }}" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 05:17, 5 July 2021
External
Internal
Overview
Loops
with_items
An iterator whose elements can be accessed with item.<element>
. The content to iterate over may came from in-line declaration or from a variable.
In-line declaration:
- name: debug
debug:
msg: "{{ item }}"
with_items:
- A
- B
- C
Variable:
- name: Find some files
find:
paths: '/some/dir'
patterns: '*.txt'
register: find_result
- name: debug
debug:
msg: "{{ item }}"
with_items: "{{ find_result.files | json_query('[*].path') }}"
loop_control
with_<lookup_plugin>
The same as loop
but adds the output of any lookup plugin to generate the item list.