W3cubDocs

/Ansible

gce_mig - Create, Update or Destroy a Managed Instance Group (MIG).

New in version 2.2.

Synopsis

Create, Update or Destroy a Managed Instance Group (MIG). See https://cloud.google.com/compute/docs/instance-groups for an overview. Full install/configuration instructions for the gce* modules can be found in the comments of ansible/test/gce_tests.py.

Requirements (on host that executes module)

  • python >= 2.6
  • apache-libcloud >= 1.2.0

Options

parameter required default choices comments
autoscaling
no
A dictionary of configuration for the autoscaler. 'enabled (bool)', 'name (str)' and policy.max_instances (int) are required fields if autoscaling is used. See https://cloud.google.com/compute/docs/reference/beta/autoscalers for more information on Autoscaling.
credentials_file
no
Path to the JSON file associated with the service account email
name
yes
Name of the Managed Instance Group.
project_id
no
GCE project ID
service_account_email
no
service account email
size
no
Size of Managed Instance Group. If MIG already exists, it will be resized to the number provided here. Required for creating MIGs.
state
no present
  • absent
  • present
desired state of the resource
template
no
Instance Template to be used in creating the VMs. See https://cloud.google.com/compute/docs/instance-templates to learn more about Instance Templates. Required for creating MIGs.
zone
yes
The GCE zone to use for this Managed Instance Group.

Examples

# Following playbook creates, rebuilds instances, resizes and then deletes a MIG.
# Notes:
# - Two valid Instance Templates must exist in your GCE project in order to run
#   this playbook.  Change the fields to match the templates used in your
#   project.
# - The use of the 'pause' module is not required, it is just for convenience.
- name: Managed Instance Group Example
  hosts: localhost
  gather_facts: False
  tasks:
    - name: Create MIG
      gce_mig:
        name: ansible-mig-example
        zone: us-central1-c
        state: present
        size: 1
        template: my-instance-template-1
    - pause: seconds=30
    - name: Recreate MIG Instances with Instance Template change.
      gce_mig:
        name: ansible-mig-example
        zone: us-central1-c
        state: present
        template: my-instance-template-2-small
        recreate_instances: yes
    - pause: seconds=30
    - name: Resize MIG
      gce_mig:
        name: ansible-mig-example
        zone: us-central1-c
        state: present
        size: 3
    - name: Update MIG with Autoscaler
      gce_mig:
        name: ansible-mig-example
        zone: us-central1-c
        state: present
        size: 3
        template: my-instance-template-2-small
        recreate_instances: yes
        autoscaling:
          enabled: yes
          name: my-autoscaler
          policy:
            min_instances: 2
            max_instances: 5
            cool_down_period: 37
            cpu_utilization:
              target: .39
            load_balancing_utilization:
              target: 0.4
    - pause: seconds=30
    - name: Delete MIG
      gce_mig:
        name: ansible-mig-example
        zone: us-central1-c
        state: absent
        autoscaling:
          enabled: no
          name: my-autoscaler

Return Values

Common return values are documented here Common Return Values, the following are the fields unique to this module:

name description returned type sample
deleted_instances Names of instances deleted. When instances are deleted. list ['ansible-mig-new-0k4y', 'ansible-mig-new-0zk5', 'ansible-mig-new-kp68']
name Name of the Managed Instance Group. changed string my-managed-instance-group
zone Zone in which to launch MIG. always string us-central1-b
created_instances Names of instances created. When instances are created. list ['ansible-mig-new-0k4y', 'ansible-mig-new-0zk5', 'ansible-mig-new-kp68']
resize_deleted_instances Names of instances deleted during resizing. When a resize results in the deletion of instances. list ['ansible-mig-new-0k4y', 'ansible-mig-new-0zk5', 'ansible-mig-new-kp68']
created_autoscaler True if Autoscaler was attempted and created. False otherwise. When the creation of an Autoscaler was attempted. bool True
recreated_instances Names of instances recreated. When instances are recreated. list ['ansible-mig-new-0k4y', 'ansible-mig-new-0zk5', 'ansible-mig-new-kp68']
template Instance Template to use for VMs. Must exist prior to using with MIG. changed string my-instance-template
updated_autoscaler True if an Autoscaler update was attempted and succeeded. False returned if update failed. When the update of an Autoscaler was attempted. bool True
resize_created_instances Names of instances created during resizing. When a resize results in the creation of instances. list ['ansible-mig-new-0k4y', 'ansible-mig-new-0zk5', 'ansible-mig-new-kp68']
deleted_autoscaler True if an Autoscaler delete attempted and succeeded. False returned if delete failed. When the delete of an Autoscaler was attempted. bool True
size Number of VMs in Managed Instance Group. changed integer 4

Notes

Note

Resizing and Recreating VM are also supported.

Note

An existing instance template is required in order to create a Managed Instance Group.

This is a Core Module

For more information on what this means please read Core Modules

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, developing_test_pr and Developing Modules.

© 2012–2016 Michael DeHaan
© 2016 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/gce_mig_module.html