gce - create or terminate GCE instances

Author:Eric Johnson <erjohnso@google.com>

Synopsis

New in version 1.4.

Creates or terminates Google Compute Engine (GCE) instances. See https://cloud.google.com/products/compute-engine for an overview. Full install/configuration instructions for the gce* modules can be found in the comments of ansible/test/gce_tests.py.

Options

parameter required default choices comments
image no debian-7
    image string to use for the instance
    instance_names no
      a comma-separated list of instance names to create or destroy
      machine_type no n1-standard-1
        machine type to use for the instance, use 'n1-standard-1' by default
        metadata no
          a hash/dictionary of custom data for the instance; '{"key":"value",...}'
          name no
            identifier when working with a single instance
            network no default
              name of the network, 'default' will be used if not specified
              persistent_boot_disk no false
                if set, create the instance with a persistent boot disk
                state no present
                • active
                • present
                • absent
                • deleted
                desired state of the resource
                tags no
                  a comma-separated list of tags to associate with the instance
                  zone yes us-central1-a
                  • us-central1-a
                  • us-central1-b
                  • us-central2-a
                  • europe-west1-a
                  • europe-west1-b
                  the GCE zone to use

                  Note

                  Requires libcloud

                  Examples


                  # Basic provisioning example.  Create a single Debian 7 instance in the
                  # us-central1-a Zone of n1-standard-1 machine type.
                  - local_action:
                      module: gce
                      name: test-instance
                      zone: us-central1-a
                      machine_type: n1-standard-1
                      image: debian-7
                  
                  # Example using defaults and with metadata to create a single 'foo' instance
                  - local_action:
                      module: gce
                      name: foo
                      metadata: '{"db":"postgres", "group":"qa", "id":500}'
                  
                  
                  # Launch instances from a control node, runs some tasks on the new instances,
                  # and then terminate them
                  - name: Create a sandbox instance
                    hosts: localhost
                    vars:
                      names: foo,bar
                      machine_type: n1-standard-1
                      image: debian-6
                      zone: us-central1-a
                    tasks:
                      - name: Launch instances
                        local_action: gce instance_names={{names}} machine_type={{machine_type}}
                                      image={{image}} zone={{zone}}
                        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 instance(s)
                    hosts: launched
                    sudo: True
                    roles:
                      - my_awesome_role
                      - my_awesome_tasks
                  
                  - name: Terminate instances
                    hosts: localhost
                    connection: local
                    tasks:
                      - name: Terminate instances that were previously launched
                        local_action:
                          module: gce
                          state: 'absent'
                          instance_names: {{gce.instance_names}}