How to take a key matches value in fact

29 views
Skip to first unread message

yuvaraj k

unread,
Apr 1, 2022, 6:33:36 AM4/1/22
to Ansible Project
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

Dick Visser

unread,
Apr 4, 2022, 6:08:05 AM4/4/22
to ansible...@googlegroups.com
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

________________________________________
From: ansible...@googlegroups.com <ansible...@googlegroups.com> on behalf of yuvaraj k <yuvi...@gmail.com>
Sent: 01 April 2022 12:33
To: Ansible Project
Subject: [ansible-project] How to take a key matches value in fact

json:


getting errror

Thanks
Yuvaraj K

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com<mailto:ansible-proje...@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a05e818d-74fe-448d-ac5a-dda2e668a969n%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/a05e818d-74fe-448d-ac5a-dda2e668a969n%40googlegroups.com?utm_medium=email&utm_source=footer>.


Reply all
Reply to author
Forward
0 new messages