ansible.builtin.gce_instance_template (v2.9.27) — module

create or destroy instance templates of Compute Engine of GCP.

| "added in version" 2.3 of ansible.builtin"

Authors: Gwenael Pellen (@GwenaelPellenArkeup) <gwenael.pellen@arkeup.com>

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.9.27

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
  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
      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
      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
      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:
    description:
    - The name of the GCE instance template.

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

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

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).

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

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

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

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

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'.

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

project_id:
    description:
    - your GCE project ID

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

description:
    description:
    - description of instance template

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.

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

image_family:
    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).

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.

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

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
    version_added: '2.4'
    version_added_collection: ansible.builtin

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)
    version_added: '2.4'
    version_added_collection: ansible.builtin

service_account_email:
    description:
    - service account email

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