简体   繁体   English

Ansible创建AWS安全组并添加到实例

[英]Ansible to create aws security group and add to instance

I am creating an EC2 instance. 我正在创建一个EC2实例。 My creation flow is, 我的创作流程是

  1. Create Ami 创建阿美

  2. Create security group 创建安全组

  3. Create new Instance from AMI and add to security group 从AMI创建新实例并添加到安全组

My new security group should only contain private ip of a new instance with appropriate ports open 我的新安全组应仅包含打开了相应端口的新实例的私有IP

My concern is, How can I create security group and add EC2 Instance private IP if that instance is yet to be created 我的担心是,如果尚未创建该实例,如何创建安全组并添加EC2实例私有IP

Is there any way that I can wait for the Instance creation task first and after it is done I fetch the private IP and use that in above task which is "Security group Creation"? 有什么方法可以首先等待实例创建任务,完成后我可以获取专用IP并将其用于上述任务中的“安全组创建”吗?

If you have any suggestions please let me know 如果您有任何建议,请让我知道

Thanks 谢谢

Is there any way that I can wait for the Instance creation task first and after it is done I fetch the private IP and use that in above task which is "Security group Creation"? 有什么方法可以首先等待实例创建任务,完成后我可以获取专用IP并将其用于上述任务中的“安全组创建”吗?

Sure, that's exactly what ec2: (or the newer ec2_instance: ) will do when given the wait: yes argument. 当然,这就是ec2:或较新的ec2_instance:在给出wait: yes参数时将要执行的操作。 By using register: ec2_result you can then use ec2_result.instances[0].private_ip_address (as seen here ) inside the ec2_group: module to define the rules for the SG. 通过使用register: ec2_result则可以使用ec2_result.instances[0].private_ip_address (如图这里 )内部ec2_group:模块定义用于SG的规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM