community.general.gce_mig (1.3.14) — module

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

Authors: Tom Melendez (@supertom) <tom@supertom.com>

Install collection

Install with ansible-galaxy collection install community.general:==1.3.14


Add to requirements.yml

  collections:
    - name: community.general
      version: 1.3.14

Description

Create, Update or Destroy a Managed Instance Group (MIG). See U(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

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
      community.general.gce_mig:
        name: ansible-mig-example
        zone: us-central1-c
        state: present
        size: 1
        template: my-instance-template-1
        named_ports:
        - name: http
          port: 80
        - name: foobar
          port: 82

    - name: Pause for 30 seconds
      ansible.builtin.pause:
        seconds: 30

    - name: Recreate MIG Instances with Instance Template change.
      community.general.gce_mig:
        name: ansible-mig-example
        zone: us-central1-c
        state: present
        template: my-instance-template-2-small
        recreate_instances: yes

    - name: Pause for 30 seconds
      ansible.builtin.pause:
        seconds: 30

    - name: Resize MIG
      community.general.gce_mig:
        name: ansible-mig-example
        zone: us-central1-c
        state: present
        size: 3

    - name: Update MIG with Autoscaler
      community.general.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

    - name: Pause for 30 seconds
      ansible.builtin.pause:
        seconds: 30

    - name: Delete MIG
      community.general.gce_mig:
        name: ansible-mig-example
        zone: us-central1-c
        state: absent
        autoscaling:
          enabled: no
          name: my-autoscaler

Inputs

    
name:
    description:
    - Name of the Managed Instance Group.
    required: true
    type: str

size:
    description:
    - Size of Managed Instance Group.  If MIG already exists, it will be resized to the
      number provided here.  Required for creating MIGs.
    type: int

zone:
    description:
    - The GCE zone to use for this Managed Instance Group.
    required: true
    type: str

state:
    choices:
    - absent
    - present
    default: present
    description:
    - desired state of the resource
    type: str

pem_file:
    description:
    - path to the pem file associated with the service account email This option is deprecated.
      Use 'credentials_file'.
    type: path

template:
    description:
    - Instance Template to be used in creating the VMs.  See U(https://cloud.google.com/compute/docs/instance-templates)
      to learn more about Instance Templates.  Required for creating MIGs.
    type: str

project_id:
    description:
    - GCE project ID
    type: str

autoscaling:
    description:
    - A dictionary of configuration for the autoscaler. 'enabled (bool)', 'name (str)'
      and policy.max_instances (int) are required fields if autoscaling is used. See U(https://cloud.google.com/compute/docs/reference/beta/autoscalers)
      for more information on Autoscaling.
    type: dict

named_ports:
    description:
    - Define named ports that backend services can forward data to.  Format is a a list
      of name:port dictionaries.
    type: list

credentials_file:
    description:
    - Path to the JSON file associated with the service account email
    type: path

recreate_instances:
    default: false
    description:
    - Recreate MIG instances.
    type: bool

service_account_email:
    description:
    - service account email
    type: str

service_account_permissions:
    description:
    - service account permissions
    type: list

Outputs

created_autoscaler:
  description: True if Autoscaler was attempted and created.  False otherwise.
  returned: When the creation of an Autoscaler was attempted.
  sample: true
  type: bool
created_instances:
  description: Names of instances created.
  returned: When instances are created.
  sample:
  - ansible-mig-new-0k4y
  - ansible-mig-new-0zk5
  - ansible-mig-new-kp68
  type: list
deleted_autoscaler:
  description: True if an Autoscaler delete attempted and succeeded. False returned
    if delete failed.
  returned: When the delete of an Autoscaler was attempted.
  sample: true
  type: bool
deleted_instances:
  description: Names of instances deleted.
  returned: When instances are deleted.
  sample:
  - ansible-mig-new-0k4y
  - ansible-mig-new-0zk5
  - ansible-mig-new-kp68
  type: list
name:
  description: Name of the Managed Instance Group.
  returned: changed
  sample: my-managed-instance-group
  type: str
named_ports:
  description: list of named ports acted upon
  returned: when named_ports are initially set or updated
  sample:
  - name: http
    port: 80
  - name: foo
    port: 82
  type: list
recreated_instances:
  description: Names of instances recreated.
  returned: When instances are recreated.
  sample:
  - ansible-mig-new-0k4y
  - ansible-mig-new-0zk5
  - ansible-mig-new-kp68
  type: list
resize_created_instances:
  description: Names of instances created during resizing.
  returned: When a resize results in the creation of instances.
  sample:
  - ansible-mig-new-0k4y
  - ansible-mig-new-0zk5
  - ansible-mig-new-kp68
  type: list
resize_deleted_instances:
  description: Names of instances deleted during resizing.
  returned: When a resize results in the deletion of instances.
  sample:
  - ansible-mig-new-0k4y
  - ansible-mig-new-0zk5
  - ansible-mig-new-kp68
  type: list
set_named_ports:
  description: True if the named_ports have been set
  returned: named_ports have been set
  sample: true
  type: bool
size:
  description: Number of VMs in Managed Instance Group.
  returned: changed
  sample: 4
  type: int
template:
  description: Instance Template to use for VMs.  Must exist prior to using with MIG.
  returned: changed
  sample: my-instance-template
  type: str
updated_autoscaler:
  description: True if an Autoscaler update was attempted and succeeded. False returned
    if update failed.
  returned: When the update of an Autoscaler was attempted.
  sample: true
  type: bool
updated_named_ports:
  description: True if the named_ports have been updated
  returned: named_ports have been updated
  sample: true
  type: bool
zone:
  description: Zone in which to launch MIG.
  returned: always
  sample: us-central1-b
  type: str