Question

I would like to create a gce instance, then run a set of tasks against it.

I have the following playbook:

- 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

the first task (create the instance) works fine, but when it gets to Configure instances I get "skipping: no hosts matched"

I am basing this playbook from example provided in the docs, and I assumed launched is a variable, but it looks like it is not.

Does anyone know how to do this?

Was it helpful?

Solution

You're missing the "add_hosts" module call from the example playbook:

- name: add_host hostname={{ item.public_ip }} groupname=new_instances

This will add the newly launched host to a group called "new_instances". Change it to "launched" for your example.

http://docs.ansible.com/guide_gce.html

Hope this helps!

-Tim

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top