How to store command output into array in Ansible?
Ansible stores the output of shell
and command
action modules in stdout
and stdout_lines
variables. The latter contains separate lines of the standard output in a form of a list.
To iterate over the elements, use:
with_items:
- "{{ annoying.stdout_lines }}"
You should remember that parsing ls
output might cause problems in some cases.