On 27.06.2019 11:17, Eric Chang wrote:
- name: get user from yml
  debug:
    msg: "{{ ch['client_hosts']['abc.com']}}"


ok: [dc053.abc.com] => {
    "msg": [
        {
            "host": "dc026",
            "ipv4": "192.168.11.26",
            "iuser": "True",
            "user": [
                "joy"
            ]
        },
        {
            "host": "dc027",
            "ipv4": "192.168.11.27"
        },
        {
            "host": "dc028",
            "ipv4": "192.168.11.28"
        },
        {
            "host": "dc032",
            "hwaddress": "30:85:a9:a3:f4:1d",
            "ipv4": "192.168.11.32"
        },
        {
            "host": "dc033",
            "hwaddress": "d8:cb:8a:c3:6a:f8",
            "ipv4": "192.168.11.33"
        },
        {
            "host": "dc034",
            "hwaddress": "70:4d:7b:a3:66:f1",
            "ipv4": "192.168.11.34",
            "iuser": "False",
            "user": [
                "changch"
            ]
        }
    ]
}


but then how do I fecth the user value only when iuser is True ?

{{ ch['client_hosts']['abc.com'] | selectattr('iuser', 'defined') | selectattr('iuser') | list }}


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

Reply via email to