Thanks, that worked. Though it feels unusual and a little like cheating Ansible.
Regards,
Uwe
Am 24.08.18 um 10:17 schrieb Kai Stian Olstad:
> On 24.08.2018 09:33, Uwe Sauter wrote:
>> I have a list of files where I need to check existence and fail if one
>> doesn't exist.
>>
>> I'd expect the fail module to *just* output the defined message when
>> the condition is true
>> but instead the complete item is printed.
>
> That's because of the with_items loop and not fail module.
>
>
>> Is there a way to make the output less verbose (but keep msg)?
>
> You could write you own callback plugin, then you can get any format you
> want, or drop loop and do it with Jinja template instead.
>
>
>> ---
>> - hosts: localhost
>> connection: local
>> gather_facts: false
>> tasks:
>> - set_fact:
>> files:
>> - /tmp/test1
>> - /tmp/test2
>>
>> - stat:
>> path: '{{ item }}'
>> with_items: '{{ files }}'
>> register: r
>>
>> - fail:
>> msg: '{{ item["invocation"]["module_args"]["path"] }} not found'
>> when: not item.stat.exists
>> with_items: ' {{ r.results }}'
>> loop_control:
>> label: '{{ item["invocation"]["module_args"]["path"] }}'
>
> Try this
>
> - fail:
> msg: Files not found {{ ', '.join(r.results | rejectattr('stat.exists')
> | map(attribute='item') | list) }}
> when: r.results | rejectattr('stat.exists') | map(attribute='item') |
> list | length > 0
>
--
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/3ae5829b-42ce-fa23-52f6-5cbf5fad1847%40gmail.com.
For more options, visit https://groups.google.com/d/optout.