0

I have the following data structure set as a fact at the end of an ansible task. I am trying to extract the SITEID's into a list.

"myoutput": [
        {
         "ID": "ZG5zLmhvc3QkLm5vbl9ETlNfaG9zdF9yb290LjAuMTUzNzE1MTcwNzgxNC5oZWxsbw", 
        "extattrs": {
            "SITEID": "10"
         }
       }, 
       {
        "ID": "r/ZG5zLmhvc3QkLm5vbl9ETlNfaG9zdF9yb290LjAuMTUzNzE1OTcyMzQzNy5ibGFo0", 
        "extattrs": {
            "SITEID": "16"
        }
    }
]

I have tried the following but this just gives me back an undefined list.

  name: write myoutput SITEID to list
   set_fact:
     mylist : "{{  host[1].extattrs | map(attribute='SITEID') | list }}"
user1768233
  • 1,409
  • 3
  • 20
  • 28

1 Answers1

1

It's as simple as:

- name: write myoutput SITEID to list
  set_fact:
    mylist: "{{ myoutput | map(attribute='extattrs.SITEID') | list }}"
techraf
  • 64,883
  • 27
  • 193
  • 198