Retrieving the dictionary key from the dictionary variable

Hi all,

Could someone please help me with the following issue.
I have created the EC2 security group using the
ec2_group module.

ec2_group
name: group name
description: group description
rules:

  • proto: tcp
    to_port: 22
    cidr_ip: 127.0.0.1

    register: sg

If I display the sg variable using the debug, I see all security group information.

Now I need to retrieve the rules array from the sg variable, actually need to retrieve the cidr_ip from rules and I am not sure how.

I tried the following: sg.rules[0].cidr_ip, gave me an incorrect variable error. It even gives me the incorrect “rules” variable if I do something like
sg.rules

However I can do sg.group_id with no problems.

So I am probably missing something simple. Could someone please tell me what is the proper way to retrieve the dictionary value, for the key, which is the dictionary or array of dictionaries itself.

Thanks so much in advance for any help.

-Igor.