【发布时间】:2021-12-27 18:57:57
【问题描述】:
我在 AWS 中有一个路由表,其中有一个子网被路由到每个主机的一个主机。我可以使用此代码自动设置这些路线:
- name: Add route to host container network
ec2_vpc_route_table:
region: region
vpc_id: "vpc-somestring"
purge_subnets: false
purge_routes: false
lookup: id
route_table_id: rtb-somestring
routes:
- dest: "1.2.3.0/24"
instance_id: "i-somestring"
这对于自动创建新主机来说很好。但是如果我想删除一个主机,我想删除匹配的路由表条目。
我想,我可以使用ec2_vpc_route_table_info 获取路由表,然后将使用rejectattr 过滤的路由反馈给ec2_vpc_route_table,替换整个表。但是,info 给了我这种格式的路由表:
"all_routes": [
{
"destination_cidr_block": "1.2.3.0/24",
"gateway_id": null,
"instance_id": "i-somestring",
"instance_owner_id": "1234567890",
"interface_id": "eni-somestring",
"network_interface_id": "eni-somestring",
"origin": "CreateRoute",
"state": "active"
},
{
"destination_cidr_block": "5.5.5.0/21",
"gateway_id": "local",
"instance_id": null,
"interface_id": null,
"network_interface_id": null,
"origin": "CreateRouteTable",
"state": "active"
},
{
"destination_cidr_block": null,
"destination_ipv6_cidr_block": "affe:affe:affe:affe::/56",
"gateway_id": "local",
"instance_id": null,
"interface_id": null,
"network_interface_id": null,
"origin": "CreateRouteTable",
"state": "active"
}
]
但是,我无法将该表提供给 ec2_vpc_route_table,因为该模块只想要一个如下所示的列表:
[
{
"dest": "1.2.3.0/24",
"instance_id": "i-somestring"
},
{
"dest": "5.5.5.0/21",
"gateway_id": "local
},
{
"dest": "affe:affe:affe:affe::/56",
"gateway_id": "local"
}
]
为什么 info 模块的输出不是我可以反馈给 route_table 模块的格式?如何将输出转换为可以反馈给 route_table 模块的格式?
感谢您的任何意见。
【问题讨论】:
标签: ansible amazon-vpc