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
当我使用 -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
IP是正确的,组名是正确的,但是当我检查ansible hosts文件时,它没有被修改。我确保在主机文件中包含 [group_name]。运行期间没有错误,不确定为什么没有将其添加到文件中。
此页面上有一个“add_host”示例:http://docs.ansible.com/ec2_module.html而 不是名称和组,它们使用主机名、组名(我认为它们是旧的)。我也试过这些。不知道我错过了什么。