noc*_*ode 2 amazon-ec2 ansible ansible-playbook ansible-inventory
Ansible版本:1.9.2
我正在运行一个将启动EC2实例的剧本.我有所有变量的site.yml并使用角色来启动EC2实例.这是ec2_launch的main.yml
---
- name: create EC2 instance
ec2:
key_name: "{{ keypair }}"
group_id: "{{ security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
region: "{{ region }}"
vpc_subnet_id: "{{ vpc_subnet_id }}"
assign_public_ip: yes
wait: True
instance_tags:
Name: "{{ instance_tag }}"
Environment: "{{ instance_tag2 }}"
exact_count: 1
count_tag:
Name: "{{ instance_tag }}"
Environment: "{{ instance_tag2 }}"
monitoring: yes
register: ec2
- name: add ec2 instance to hosts
add_host: name={{ item.private_ip }} groups=group_name
with_items: ec2.instances
- name: wait for SSH
wait_for: host={{ item.private_ip }} port=22 delay=60 timeout=320 state=started
with_items: ec2.instances
Run Code Online (Sandbox Code Playgroud)
当我使用-vvv选项运行时,这是add_hosts期间的输出:
TASK: [ec2_launch | add ec2 instance to hosts] ********************************
creating host via 'add_host': hostname=10.50.101.93
added host to group via add_host module: group_name
Run Code Online (Sandbox Code Playgroud)
IP是正确的,组名是正确的但是当我检查ansible hosts文件时,它还没有被修改.我确保在hosts文件中包含[group_name].在运行期间没有错误,并且不确定为什么它没有被添加到文件中.
这个页面上有一个'add_host'示例:http://docs.ansible.com/ec2_module.html 而不是名称和组,它们使用主机名,组名(我相信这是旧的).我也尝试过这些.不知道我错过了什么.
在add_host没有任务不将它添加到主文件,它把它添加到主机的内存列表.
添加到hosts文件在所有情况下都不起作用 - 例如,AWS用户经常使用./ec2.py脚本,该脚本是替换其基于文本的主机文件的二进制可执行文件.
| 归档时间: |
|
| 查看次数: |
5003 次 |
| 最近记录: |