# How to get if key ==matches to get value, Please help on this.

**URL:** <https://forum.ansible.com/t/how-to-get-if-key-matches-to-get-value-please-help-on-this/36503>\
**Category:** Ansible Project\
**Created:** [April 4, 2022, 3:57am UTC](https://forum.ansible.com/t/how-to-get-if-key-matches-to-get-value-please-help-on-this/36503 "2022-04-04T03:57:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuvaraj\_k](https://avatars.discourse-cdn.com/v4/letter/y/ba8739/32.png) [@yuvaraj\_k](https://forum.ansible.com/u/yuvaraj_k)\
**Post date:** [April 4, 2022, 3:57am UTC](https://forum.ansible.com/t/how-to-get-if-key-matches-to-get-value-please-help-on-this/36503/1 "2022-04-04T03:57:57Z")

</div>

Input 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”

}  
]  
}

**ec2\_asg.yaml:**

- 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**’) }}”

How to get the key matches and value return , i am getting error.

Thanks &Regards,  
Yuvaraj K
