community.general.gce_instance_template (1.3.14) — module

create or destroy instance templates of Compute Engine of GCP.

Authors: Gwenael Pellen (@GwenaelPellenArkeup) <gwenael.pellen@arkeup.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

Creates or destroy Google instance templates of Compute Engine of Google Cloud Platform.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Usage
- name: Create instance template named foo
  community.general.gce_instance_template:
    name: foo
    size: n1-standard-1
    image_family: ubuntu-1604-lts
    state: present
    project_id: "your-project-name"
    credentials_file: "/path/to/your-key.json"
    service_account_email: "your-sa@your-project-name.iam.gserviceaccount.com"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Example Playbook
- name: Compute Engine Instance Template Examples
  hosts: localhost
  vars:
    service_account_email: "your-sa@your-project-name.iam.gserviceaccount.com"
    credentials_file: "/path/to/your-key.json"
    project_id: "your-project-name"
  tasks:
    - name: Create instance template
      community.general.gce_instance_template:
        name: my-test-instance-template
        size: n1-standard-1
        image_family: ubuntu-1604-lts
        state: present
        project_id: "{{ project_id }}"
        credentials_file: "{{ credentials_file }}"
        service_account_email: "{{ service_account_email }}"
    - name: Delete instance template
      community.general.gce_instance_template:
        name: my-test-instance-template
        size: n1-standard-1
        image_family: ubuntu-1604-lts
        state: absent
        project_id: "{{ project_id }}"
        credentials_file: "{{ credentials_file }}"
        service_account_email: "{{ service_account_email }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Example playbook using disks_gce_struct
- name: Compute Engine Instance Template Examples
  hosts: localhost
  vars:
    service_account_email: "your-sa@your-project-name.iam.gserviceaccount.com"
    credentials_file: "/path/to/your-key.json"
    project_id: "your-project-name"
  tasks:
    - name: Create instance template
      community.general.gce_instance_template:
        name: foo
        size: n1-standard-1
        state: present
        project_id: "{{ project_id }}"
        credentials_file: "{{ credentials_file }}"
        service_account_email: "{{ service_account_email }}"
        disks_gce_struct:
          - device_name: /dev/sda
            boot: true
            autoDelete: true
            initializeParams:
              diskSizeGb: 30
              diskType: pd-ssd
              sourceImage: projects/debian-cloud/global/images/family/debian-8

Inputs

    
name:
    aliases:
    - base_name
    description:
    - The name of the GCE instance template.
    required: true
    type: str

size:
    default: f1-micro
    description:
    - The desired machine type for the instance template.
    type: str

tags:
    description:
    - a comma-separated list of tags to associate with the instance
    type: list

disks:
    description:
    - a list of persistent disks to attach to the instance; a string value gives the name
      of the disk; alternatively, a dictionary value can define 'name' and 'mode' ('READ_ONLY'
      or 'READ_WRITE'). The first entry will be the boot disk (which must be READ_WRITE).
    type: list

image:
    description:
    - The image to use to create the instance. Cannot specify both both I(image) and I(source).
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - The desired state for the instance template.
    type: str

source:
    description:
    - A source disk to attach to the instance. Cannot specify both I(image) and I(source).
    type: str

network:
    default: default
    description:
    - The network to associate with the instance.
    type: str

metadata:
    description:
    - a hash/dictionary of custom data for the instance; '{"key":"value", ...}'

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

disk_type:
    choices:
    - pd-standard
    - pd-ssd
    default: pd-standard
    description:
    - Specify a C(pd-standard) disk or C(pd-ssd) for an SSD disk.
    type: str

project_id:
    description:
    - your GCE project ID
    type: str

subnetwork:
    description:
    - The Subnetwork resource name for this instance.
    type: str

description:
    description:
    - description of instance template
    type: str

external_ip:
    default: ephemeral
    description:
    - The external IP address to use. If C(ephemeral), a new non-static address will be
      used.  If C(None), then no external address will be used.  To use an existing static
      IP address specify address name.
    type: str

preemptible:
    description:
    - Defines whether the instance is preemptible.
    type: bool

image_family:
    default: debian-8
    description:
    - The image family to use to create the instance. If I(image) has been used I(image_family)
      is ignored. Cannot specify both I(image) and I(source).
    type: str

can_ip_forward:
    default: 'no'
    description:
    - Set to C(yes) to allow instance to send/receive non-matching src/dst packets.
    type: bool

nic_gce_struct:
    description:
    - Support passing in the GCE-specific formatted networkInterfaces[] structure.
    type: list

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

disk_auto_delete:
    default: true
    description:
    - Indicate that the boot disk should be deleted when the Node is deleted.
    type: bool

disks_gce_struct:
    description:
    - Support passing in the GCE-specific formatted formatted disks[] structure. Case
      sensitive. see U(https://cloud.google.com/compute/docs/reference/latest/instanceTemplates#resource)
      for detailed information
    type: list

automatic_restart:
    description:
    - Defines whether the instance should be automatically restarted when it is terminated
      by Compute Engine.
    type: bool

subnetwork_region:
    description:
    - Region that subnetwork resides in. (Required for subnetwork to successfully complete)
    type: str

service_account_email:
    description:
    - service account email
    type: str

service_account_permissions:
    description:
    - service account permissions (see U(https://cloud.google.com/sdk/gcloud/reference/compute/instances/create),
      --scopes section for detailed information)
    - 'Available choices are: C(bigquery), C(cloud-platform), C(compute-ro), C(compute-rw),
      C(useraccounts-ro), C(useraccounts-rw), C(datastore), C(logging-write), C(monitoring),
      C(sql-admin), C(storage-full), C(storage-ro), C(storage-rw), C(taskqueue), C(userinfo-email).

      '
    type: list