Output from "fail" too verbose

Hi all,

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.

Is there a way to make the output less verbose (but keep msg)?

Thanks,

  Uwe

#### playbook ####

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

Thanks, that worked. Though it feels unusual and a little like cheating Ansible.

Regards,

  Uwe