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

--
Kai Stian Olstad

--
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/202bbd9926df8e7c0edc636cbfe0bea9%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to