mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
Support iteration over command output in with_items.
When the output of a command is stored in a register, this will create a stdout_lines field in the result object that contains stdout split into a list of lines. This list can then be iterated over using with_items.
This commit is contained in:
19
test/results_list.yml
Normal file
19
test/results_list.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
# Test iterating over lines of stdout stored in a register.
|
||||
- hosts: localhost
|
||||
vars:
|
||||
small_file: /etc/resolv.conf
|
||||
temp_file: /tmp/ansible_result_list.tmp
|
||||
|
||||
tasks:
|
||||
- action: command cat $small_file
|
||||
register: result
|
||||
|
||||
- action: file dest=$temp_file state=absent
|
||||
|
||||
- action: shell echo '$item' >> $temp_file
|
||||
with_items: ${result.stdout_lines}
|
||||
|
||||
- action: command diff $small_file $temp_file
|
||||
|
||||
- action: file dest=$temp_file state=absent
|
||||
Reference in New Issue
Block a user