【发布时间】:2018-01-14 07:17:51
【问题描述】:
我在 aws 上有 3 个独立的 VPC,并且正在使用 ansible 来处理部署。我的问题是我的一些环境使用来自另一个 VPC 的安全组。
这是我的 EC2 模块 -
- name: Create instance
ec2:
image: "{{ image }}"
instance_type: "{{ instance_type }}"
aws_access_key: "{{ aws_access_key_id }}"
aws_secret_key: "{{ aws_secret_access_key }}"
key_name: "{{ key_name }}"
instance_tags:
Name: "{{ name }}"
Environment: "{{ env }}"
Product: "{{ product }}"
Service: "{{ service }}"
region: "{{ region }}"
volumes:
- device_name: "{{ disk_name }}"
volume_type: "{{ disk_type }}"
volume_size: "{{ disk_size }}"
delete_on_termination: "{{ delete_on_termination }}"
# group: "{{ security_group_name }}"
group_id: "{{ security_group_id }}"
wait: true
vpc_subnet_id: "{{ vpc_subnet_id }}"
count: "{{ instance_count }}"
monitoring: "{{ detailed_monitoring }}"
instance_profile_name: "{{ iam_role }}"
assign_public_ip: "{{ assign_public_ip }}"
termination_protection: "{{ termination_protection }}"
register: ec2
当我从另一个 VPC 传入安全组 ID 时,我得到了这个 -
"msg": "Instance creation failed => InvalidParameter: Security group sg-e7284493 and subnet subnet-19d97e50 belong to different networks."
Ansible 中有解决方法吗?
【问题讨论】:
-
“使用来自另一个 VPC 的安全组”你能澄清你的意思吗?您的意思是您正在使用具有对等连接的多个 VPC 并尝试从对等 VPC 引用安全组?
-
是的,我有 3 个独立的 VPC,它们相互之间有对等连接。我可以在 aws 上的 SG 中引用外国 SG,但是在通过 ansible 创建 EC2 时我无法引用外国 SG。这可能吗?
-
我认为您将引用安全组与分配安全组混淆了。在这个 Ansible 任务中,
ec2模块将安全组分配给实例。在 VPC 对等关系中,您只能引用安全组规则内的安全组。您必须在同一 VPC 中创建一个新的安全组(可能使用ec2_group模块),该安全组具有引用另一个 VPC 中的安全组的规则。 -
感谢您的帮助,我想我会创建几个重复的安全组。
标签: amazon-web-services amazon-ec2