获取使用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服务器.
有可能吗?
推荐答案
阅读 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实例添加到带有关联的ec2 pem文件的Ansible动态创建的主机组中(以便您可以ssh对其添加)
- 调用带有ping任务的示例游戏以显示一切正常
注意:您将用您的一组任务替换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屋!