I've figured it out.

Thanks for the o.p and the contributor solution !

---
- hosts: localhost
tasks:
- name: Stat filesystems
stat: path="{{ item }}"
with_items:
- /dev
- /home
register: filesystems_stat

- name: Confirming ownership of filesystems
loop: |
{{ filesystems_stat.results | map(attribute='item')
| zip(filesystems_stat.results | map(attribute='stat.pw_name'))
| list }}

assert:
that: item.1 == 'root'
loop_control:
label: "{{ item.0 }}"

On Saturday, December 19, 2020 at 10:10:18 AM UTC-5 Thuan wrote:

> Hi,
>
> I have the same issue.
> I tried this method but it didn't work on Ansible 2.9.16.
> Am I missing something ?
>
>
> ---
> - hosts: localhost
>   tasks:
>   - name: Stat filesystems
>     stat: path="{{ item }}"
>     with_items:
>       - /dev
>       - /home
>     register: filesystems_stat
>
>   - name: Confirming ownership of filesystems
>     loop: | 
>           {{ filesystems_stat.results | map(attribute='item')
>           | zip(filesystems_stat.results | map(attribute='stat.pw_name'))
>           | list }}
>     loop_control:
>     label: "{{ item.item }}"
>     
>
>   - assert:
>       that: item.1 == 'root'
>     loop_control:
>       label: "{{ item.0 }}"
>
>
> On Monday, February 11, 2019 at 2:00:16 PM UTC-5 [email protected] 
> wrote:
>
>> Thanks Felix.  Working on a PR now.
>>
>> Rob
>>
>> On Sat, Feb 9, 2019 at 10:18 AM 'Felix Fontein' via Ansible Project <
>> [email protected]> wrote:
>>
>>> Hi Rob,
>>>
>>> > So I noticed that older versions (2.1.1) of ansible didn't have this
>>> > problem, and I noticed that the verbosity of assert is caused by the
>>> > following line in assert.py:
>>> > 
>>> > result['_ansible_verbose_always'] = True
>>> > 
>>> > If I comment that out, I get the quieter behavior I (and others,
>>> > based on some reported github issues) am looking for.  So can anyone
>>>
>>> I assume you are talking about this issue:
>>> https://github.com/ansible/ansible/issues/27124
>>>
>>> > explain the purpose of the above line? What is
>>> > _ansible_verbose_always for?
>>>
>>> That's easy: it makes the module behave as if -v is specified on the
>>> ansible command line: it always produces verbose output when the assert
>>> module is used.
>>>
>>> > Why was it added to assert.py?
>>>
>>> That's a good one. As you probably read in the issue, nobody remembers,
>>> so it is unlikely someone suddenly can provide an explanation here :)
>>>
>>> > Could I add another parameter to assert.py (maybe quiet) and, if set
>>> > to True, then do not set result['_ansible_verbose_always'] to True?
>>>
>>> Sure; that's essentially what @bcoca suggested here:
>>> https://github.com/ansible/ansible/issues/27124#issuecomment-316855948
>>>
>>> Feel free to create a PR which does that.
>>>
>>> Cheers,
>>> Felix
>>>
>>>
>>>
>>> > I appreciate I'm
>>> > getting into the weeds here, but I found it curious that assert got
>>> > noisy in more recent versions.
>>> > 
>>> > Rob
>>> > 
>>> > On Wed, Feb 6, 2019 at 12:36 PM Rob Wagner <[email protected]>
>>> > wrote:
>>> > 
>>> > > 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
>>>
>>> -- 
>>> 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/20190209161838.5a861dcc%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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a2862abe-231d-4714-9994-9fd9b256e445n%40googlegroups.com.

Reply via email to