The "problem" is in how ansible registers results when using with_items.
It nests all of the results inside of a `results` key
Your second task could have been written to use:
- name: use shell to print list of file paths
shell: "echo {{ item }}"
with_items: "{{ files.results|map(attribute='stdout_lines')|list }}"
That would do it for you. That pulls the `stdout_lines` attribute out into
a list of `stdout_lines`, then with_items natively handles the flattening,
allowing you to loop over each individual item in the `ls` output.
There is some documentation about using register with a loop, which you can
find at
http://docs.ansible.com/ansible/playbooks_loops.html#using-register-with-a-loop
On Tue, Feb 23, 2016 at 12:51 PM, Jason Gilfoil <[email protected]> wrote:
> So after some testing and reading i'm gonna attempt to answer my own
> question, and pose another one.
>
> The documentation I cited for iterating the results of a program execution
> didn't involve the use of with_items in the original program execution.
> Having multiple results in a register variable doesn't seem to play nice
> with 'with_items'.
>
> I decided to work around the issue by having multiple tasks to gather the
> file names and iterate over each result in the replace module.
>
> As a corollary to that, when using with_items and setting a failed_when
> condition, you can't seem to use the 'rc' property of the register variable
> in a task because the rc code only exists if the task fails. I'm thinking
> there must be a way to say fail_when: the register.rc exists, but haven't
> figured that part out yet.
>
>
> On Monday, February 22, 2016 at 10:19:47 AM UTC-5, Jason Gilfoil wrote:
>>
>> Hello All,
>>
>> I'm ultimately attempting to pull a list of files with wildcarded paths
>> and pass the results into the replace module so it can cycle through them
>> all. However, starting with a more simple example, i'm having issues
>> getting the list of files to print properly in even a simple test case.
>>
>>
>> Pastebin code:
>> http://pastebin.com/zFRzucat
>>
>> I'm looking for this:
>>
>> test.yml playbook
>>
>> - hosts: all
>> tasks:
>> - name: gather list of files
>> shell: ls {{ item }}
>> register: files
>> with_items:
>> - /app/psoft/test/*/list.txt
>> - /app/psoft/test/*/context.xml
>>
>> - name: use shell to print list of file paths
>> shell: "echo {{ item }}"
>> with_items: "{{files.stdout_lines}}"
>>
>>
>> to print
>>
>> /app/psoft/test/12.1.2.00/list.txt
>> /app/psoft/test/12.1.3.00/context.xml
>>
>> However currently the result is:
>>
>> TASK [gather list of files]
>> ****************************************************
>> changed: [net12204] => (item=/app/psoft/test/*/list.txt)
>> changed: [net12204] => (item=/app/psoft/test/*/context.xml)
>>
>> TASK [use shell to print list of file paths]
>> ***********************************
>> [DEPRECATION WARNING]: Skipping task due to undefined attribute, in the
>> future this will be a fatal error.. This feature will
>> be removed in a future release. Deprecation warnings can be disabled by
>> setting deprecation_warnings=False in ansible.cfg.
>>
>>
>> Am I misusing or not understanding
>> http://docs.ansible.com/ansible/playbooks_loops.html#iterating-over-the-results-of-a-program-execution
>> properly?
>>
>>
>> Thanks!
>> Jason
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/82ae7301-06d6-42e9-a4f3-cf017f09ed22%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/82ae7301-06d6-42e9-a4f3-cf017f09ed22%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
Matt Martz
@sivel
sivel.net
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAD8N0v-_iuDcNNvFmNcAkhUrb_uZgfgDsWfnk_BzUn-f0d%3D%2BSw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.