Loop over list of dicts in ansible

I have a list of dicst like this -

“lv”: [
{
“CreatedDate”: “2020-06-23T16:49:55.504+0000”,
“Description”: “Layer 0”,
“LayerVersionArn”: “arn:aws:lambda:us-east-1”,
“Version”: 10
},
{
“CreatedDate”: “2020-06-23T16:44:26.011+0000”,
“Description”: “Layer 1”,
“LayerVersionArn”: “arn:aws:lambda:us-east-1”,
“Version”: 9
}
]

I want to get the list of Version (10 and 9 above) field from the list. Note - Number of elements in the list is not static.

Try this

  - set_fact:
      versions: "{{ lv|map(attribute='Version')|list }}"

Thanks Vladimir.

This also worked-

  • set_fact:
    versions: “{{ (lv | json_query(‘[*].Version’) }}”