Amazon web services Ansible AWS创建按实例标记分组的IP地址的dict

Amazon web services Ansible AWS创建按实例标记分组的IP地址的dict,amazon-web-services,ansible,Amazon Web Services,Ansible,我有几个EC2实例,需要从中提取IP地址,并根据特定的实例标记对它们进行分组 因此,这个示例JSON: { "changed": true, "instances": [ { "ami_launch_index": 0, "architecture": "x86_64", "private_ip_address": "11.111.1.111", "public_d

我有几个EC2实例,需要从中提取IP地址,并根据特定的实例标记对它们进行分组

因此,这个示例JSON:

{
    "changed": true,
    "instances": [ 
        {
            "ami_launch_index": 0,
            "architecture": "x86_64",
            "private_ip_address": "11.111.1.111", 
            "public_dns_name": "",
            "tags": {
                "Environment": "dev",
                "Role": "role1",
            }
        },
        { 
            "ami_launch_index": 0,
            "architecture": "x86_64",
            "private_ip_address": "22.222.2.222",
            "public_dns_name": "",
            "tags": {
                "Environment": "dev",
                "Role": "role1",
            }
        },
        {
            "ami_launch_index": 0,
            "architecture": "x86_64",
            "private_ip_address": "33.333.3.333",
            "public_dns_name": "",
            "tags": {
                "Environment": "dev",
                "Role": "role2",
            }
        },
        {
            "ami_launch_index": 0,
            "architecture": "x86_64",
            "private_ip_address": "44.444.4.444",
            "public_dns_name": "",
            "tags": {
                "Environment": "dev",
                "Role": "role2",
            }
        }
    ]
}
将产生以下结果:

{
    "role1": [
        "11.111.1.111",
        "22.222.2.222"
    ],
    "role2": [
        "33.333.3.333",
        "44.444.4.444"
    ]
}
从AWS获取实例信息没有问题,但我正在努力创建包含IP地址分组列表的字典。我尝试了中提供的几种解决方案,但没有任何运气

给你:

- set_fact:
    my_result: "{{ my_result | default({}) | combine({item.0: item.1|map(attribute='private_ip_address')|list}) }}"
  loop: "{{ my_input.instances|groupby('tags.Role') }}"

我认为这可能与映射过滤器有关,但我完全没有看到文档中的“属性”部分。非常感谢。