Building a list from complex YAML

19 views
Skip to first unread message

Francois Herbet

unread,
Jul 24, 2017, 4:34:12 PM7/24/17
to Ansible Project

Hi Guys need some advice on this case


here's my hostvars

---
SERVICE:
    MC:
        GS_SIGMAX_MC_A_import:
            PIM_GROUP: GS_SIGMAX_MC_A_PIM
        GS_SIGMAY_MC_A_import:
            PIM_GROUP: GS_SIGMAY_MC_A_PIM



i'd like to populate a list of "PIM_GROUP" values whatver the previous dict name is (xxx_import)



currently this task

 -  debug: msg="{{ item }}"
    with_items:
      - "{{ SERVICE.MC }}"



gives :

"item": {
        "GS_SIGMAX_MC_A_import": {
            "PIM_GROUP": "GS_SIGMAX_MC_A_PIM"
        },
        "GS_SIGMAY_MC_A_import": {
            "PIM_GROUP": "GS_SIGMAY_MC_A_PIM"
        }
    },
    "msg": {
        "GS_SIGMAX_MC_A_import": {
            "PIM_GROUP": "GS_SIGMAX_MC_A_PIM"
        },
        "GS_SIGMAY_MC_A_import": {
            "PIM_GROUP": "GS_SIGMAY_MC_A_PIM"
        }
    }






do i need json_query  for that or there's an easier way ?


thanks !

\\ François

Francois Herbet

unread,
Jul 24, 2017, 5:09:41 PM7/24/17
to Ansible Project
look like i've the proper json_query







 -  debug: msg="{{ item }}"
    with_items:
      - "{{ SERVICE.MC|json_query('*.PIM_GROUP') }}"

which gives

    "msg": [
        "GS_SIGMAX_MC_A_PIM",
        "GS_SIGMAY_MC_A_PIM"
    ]
Reply all
Reply to author
Forward
0 new messages