我想创建一个 gce 实例
,然后针对它运行一组任务。
我有以下剧本:
- name: Create instances
hosts: localhost
tasks:
- name: Launch instances
local_action: gce instance_names=queue
machine_type=f1-micro
image=debian-7
zone=europe-west1-a
tags=queue
register: gce
- name: Wait for SSH to come up
local_action: wait_for host="{{ item.public_ip }}"
port=22
delay=10
timeout=60
state=started
with_items: "{{ gce.instance_data }}"
- name: Configure instances
hosts: launched
sudo: True
roles:
- my_role_1
- my_role_1
第一个任务(创建实例)工作正常,但是当它到达配置实例
时,我得到
“跳过:没有匹配的主机”
我将此剧本基于 docs 中提供的示例,我假设 launched
是一个变量,但看起来不是。
有人知道怎么做吗?
最佳答案
您缺少示例 playbook 中的“add_hosts”模块调用:
- name: add_host hostname={{ item.public_ip }} groupname=new_instances
这会将新启动的主机添加到名为“new_instances”的组中。对于您的示例,将其更改为“启动”。
http://docs.ansible.com/guide_gce.html
希望这有帮助!
-蒂姆
关于ansible 创建 gce 实例然后对其执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23451502/