Another way you could be as below:
---
- hosts: localhost
  connection: local
  gather_facts: false
  vars:
    tests:
      test1:
        name: A
        age: 12
        gender: M

      test2:
        name: K
        age: 10
        gender: F

  tasks:
    - debug: msg="{{ item }} name={{ tests[item]['name'] }} age={{ 
tests[item]['age'] }} gender={{ tests[item]['gender'] }}"
      with_items: "{{ tests }}"


Results in:
ok: [localhost] => (item=test1) => {
    "changed": false,
    "item": "test1",
    "msg": "test1 name=A age=12 gender=M"
}
ok: [localhost] => (item=test2) => {
    "changed": false,
    "item": "test2",
    "msg": "test2 name=K age=10 gender=F"
}


On Saturday, December 9, 2017 at 12:43:04 PM UTC-5, Saurabh Pal wrote:
>
> How to read variables in ansible? 
>
> Below Example : 
>
> --- 
>   hosts: localhost
>   vars: 
>      test1:
>         name: A
>         age: 12
>         gender: M
>
>       test2: 
>         name: K
>         age: 10
>         gender: F
>
> so on .... like test 10 ....
>
> - tasks: 
>    debug : msg : --> 
>
> how to print variables based in taking array or key values?
>
>
>    
>
>

-- 
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/dcedcd18-d5a0-4a53-bc05-3df600ffaff6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to