I have a yml file named: client_hosts.yml
it looks like below

client_hosts:
>   abc.com:
>   - host: dc021
>     ipv4: 192.168.11.21
>   - host: dc022
>     ipv4: 192.168.11.22
>   - host: dc023
>     ipv4: 192.168.11.23
>     iuser: True
>     user: john
>   - host: dc024
>     ipv4: 192.168.11.24
>   - host: dc025
>     ipv4: 192.168.11.25
>     iuser: True
>     user: Mary
>   - host: dc026
>     ipv4: 192.168.11.26
>   - host: dc027
>     ipv4: 192.168.11.27
>   - host: dc028
>     ipv4: 192.168.11.28
>   - host: dc029
>     ipv4: 192.168.11.29
>

I want to select user with iuser=True
so I create a playbook , include the file

with the code below , I can get a list.

- name: load client_host
  include_vars:
    file: client_hosts.yml
    name: ch

- 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 ?



-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9808f01a-4aaf-4046-b9f7-73112a796a25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to