How to take a key matches value in fact

json:

“ec2_asg”: {
“changed”: false,
“failed”: false,
“results”: [

{
“tags”: [
{
“key”: “peer_discovery_backend”,
“propagate_at_launch”: true,
“resource_id”: “AnsibleASG”,
“resource_type”: “auto-scaling-group”,
“value”: “Rabbitmq”

}
]
}

  • name: Find a group with matching name/prefix and tags
    ec2_asg_info:
    name: “{{ AUTOSCALING_GROUP_NAME }}”
    register: ec2_asg

  • name: ASG Facts
    set_fact:
    PEER_DISCOVERY_BACKEND: “{{ec2_asg | json_query('ec2_asg.results[0].tags[0][?key==‘peer_discovery_backend’].value’) }}”

getting errror

Thanks
Yuvaraj K

Try:

    - name: ASG Facts
      set_fact:
        PEER_DISCOVERY_BACKEND: "{{ ec2_asg|json_query('results[0].tags[?key==`peer_discovery_backend`]|[0].value') }}"

Dick Visser
GÉANT