获取使用 Ansible 创建的 AWS 实例的 IP 地址/属性 [英] Getting the IP address/attributes of the AWS instance created using Ansible
问题描述
我知道如何使用 Ansible 创建 AWS 实例.现在我想要实现的是通过使用创建实例的相同剧本安装 nginx 将该实例配置为 Web 服务器.
I know how to create an AWS instance using Ansible. Now what I want to achieve is to configure that instance as web server by installing nginx using the same playbook which created the instance.
剧本的目标是:
- 创建一个 AWS 实例.
- 通过设置 Nginx 服务器将实例配置为 Web 服务器.
ansible 可以吗?
Is it possible with ansible?
推荐答案
阅读 http://www.ansible.com/blog/ansible-ec2-tags 它详细说明了如何启动一个 ec2 实例(或多个),然后针对它运行任务(即安装 nginx).
Read http://www.ansible.com/blog/ansible-ec2-tags It details how to spin up an ec2 instance (or multiple) and then run tasks against it (I.e install nginx).
如果您想直接跳到示例手册 https://github.com/chrismeyersfsu/playbook-ec2_properties/blob/master/new_group.yml
I'f you want to jump straight to the example playbook https://github.com/chrismeyersfsu/playbook-ec2_properties/blob/master/new_group.yml
- 启动 ec2 实例
- 等待 ssh
- 将 ec2 实例添加到 Ansible 动态创建的主机组,并带有关联的 ec2 pem 文件(以便您可以通过 ssh 连接到它)
- 调用一个带有 ping 任务的示例 play 以显示一切正常
注意:您将使用您的一组任务替换 ping 任务以安装 nginx
Note: you would replace the ping task with your set of tasks to install nginx
@Bidyut 如何引用ec2 ip地址
查看第27行 注意使用register: ec2
然后在第46行 ec2 ip 地址被提取"{{ ec2.results[item.0]['instances'][0]['public_ip'] }}
.请注意,该示例在循环中调用 register
.如果您只是创建一个 ec2 实例,那么 ec2 ip 地址引用将类似于 {{ ec2.results['instances'][0]['public_ip'] }}
look at Line 27 Note the use of register: ec2
Then at Line 46 the ec2 ip address is "extracted" {{ ec2.results[item.0]['instances'][0]['public_ip'] }}
. Note that the example calls register
within a loop. If you are just creating one ec2 instance then the ec2 ip address reference would look like {{ ec2.results['instances'][0]['public_ip'] }}
这篇关于获取使用 Ansible 创建的 AWS 实例的 IP 地址/属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!