ansible 创建 gce 实例然后对其执行操作

标签 ansible

我想创建一个 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/

相关文章:

git - 使用 Ansible 从 Bitbucket 克隆一个 git repo - 要求密码两次或三次

安西 bool 。如何从组中选择N个主机

powershell - Ansible中的Powershell脚本

ansible - 使ansible根据变量多次运行剧本中的任务

amazon-web-services - 使用 Ansible 创建 Elasticache 时出现默认子网错误

docker - 如何使用 Ansible 启动 Docker 容器

ansible - 如何让ansible只在需要时才要求输入密码

ansible - 清除Ansible-Playbook中的错误输出

python - 如何从 Python 脚本中查看/解密 Ansible 保险库凭据文件?

docker - Ansible 不允许我通过 SSH 连接