Thanks Felix.  That's a clever idea.  I tested it and I get:

ok: [localhost] => (item=/dev) => {
    "changed": false,
    "item": [
        "/dev",
        "root"
    ],
    "msg": "All assertions passed"
}
ok: [localhost] => (item=/home) => {
    "changed": false,
    "item": [
        "/home",
        "root"
    ],
    "msg": "All assertions passed"
}

I don't really understand why it needs to include "item" in the dict (i.e.,
after => ), since it's already present in the output (i.e., before => ),
but this is better than the original.  Thanks again.

Rob

On Wed, Jan 30, 2019 at 3:43 PM 'Felix Fontein' via Ansible Project <
[email protected]> wrote:

> Hi Rob,
>
> > Hey Felix - can you elaborate?  I'm already using:
> >
> > loop_control:
> >       label: "{{ item.item }}"
> >
> > As shown in my post.  It doesn't quench the output of the items.  Am
> > I missing something?
>
> sorry, I guess I misunderstood something. The problem is that assert
> always enables verbose output, so you cannot get rid of item
> completely. What you can do is tidy up item so only the important
> things are in there.
>
> You could try something like
>
>   loop: |
>     {{ filesystems_stat.results | map(attribute='item')
>      | zip(filesystems_stat.results | map(attribute='stat.pw_name'))
>      | list }}
>
> Then you should be able to access item.item via item.0 and
> item.stat.pw_name via item.1, i.e. the rest of the task would be
>
>   assert:
>     that: item.1 == 'root'
>   loop_control:
>     label: "{{ item.0 }}"
>
> (I haven't tested this, so it might contain bugs, but in principle that
> should work. Note that the zip filter is Ansible specific, while the
> map and list filters are generic Jinja2.)
>
> (Also: with_items does the same as loop if you give it a simple list;
> you should switch to loop in such cases, and stop using with_items if
> not explicitly needed.)
>
> Cheers,
> Felix
>
>
>
> >
> > Rob
> >
> > On Monday, January 28, 2019 at 2:11:57 PM UTC-5, Felix Fontein wrote:
> > >
> > > Hi,
> > >
> > > check out the label directive for loop_control:
> > >
> > >
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#loop-control
> > >
> > > Cheers,
> > > Felix
> > >
> > >
> > >
> > > On Mon, 28 Jan 2019 07:54:39 -0800 (PST)
> > > [email protected] <javascript:> wrote:
> > >
> > > > Hey all-
> > > >
> > > > I'm using stat and with_items to check proper ownership of
> > > > various files. Is there any way to reduce the volume of output
> > > > (i.e., eliminate everything in red, below)?
> > > >
> > > > rowagn@localhost:~/data-platform/oracle/ansible/db12r2$ cat
> > > > test.yml ---
> > > > - hosts: localhost
> > > >   tasks:
> > > >   - name: Stat filesystems
> > > >     stat: path="{{ item }}"
> > > >     with_items:
> > > >       - /dev
> > > >       - /home
> > > >     register: filesystems_stat
> > > >
> > > >   - name: Confirming ownership of filesystems
> > > >     assert:
> > > >       that: "{{ item.stat.pw_name == 'root' }}"
> > > >     with_items: "{{ filesystems_stat.results }}"
> > > >     loop_control:
> > > >       label: "{{ item.item }}"
> > > >
> > > >   - name: Stat filesystem no with_items
> > > >     stat: path="/dev"
> > > >     register: dev_stat
> > > >
> > > >   - name: Confirming ownership of dev
> > > >     assert:
> > > >       that: "{{ dev_stat.stat.pw_name == 'root' }}"
> > > >
> > > > rowagn@localhost:~/data-platform/oracle/ansible/db12r2$
> > > > ansible-playbook -i "localhost," -c local test.yml
> > > >
> > > > PLAY [localhost]
> > > > ***************************************************************
> > > >
> > > > TASK [setup]
> > > > *******************************************************************
> > > > ok: [localhost]
> > > >
> > > > TASK [Stat filesystems]
> > > > ********************************************************
> > > > ok: [localhost] => (item=/dev)
> > > > ok: [localhost] => (item=/home)
> > > >
> > > > TASK [Confirming ownership of filesystems]
> > > > *************************************
> > > > ok: [localhost] => (item=/dev) => {
> > > >     "changed": false,
> > > >     "item": {
> > > >         "changed": false,
> > > >         "invocation": {
> > > > [...]
> > >
> >
>
>
> --
> Felix Fontein -- [email protected] -- https://felix.fontein.de/
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/XRfVnH088fk/unsubscribe.
> To unsubscribe from this group and all its topics, 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/20190130214324.6f725e36%40rovaniemi
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAMc-rNP5Y9XUDvaPtJ5TOsvd48jSNn%2BvdOcuVmbnbPmdY9y6rw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to