community.google.gce_instance_template module – create or destroy instance templates of Compute Engine of GCP.
Note
This module is part of the community.google collection (version 1.0.0).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install community.google
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.google.gce_instance_template
.
Synopsis
Creates or destroy Google instance templates of Compute Engine of Google Cloud Platform.
Requirements
The below requirements are needed on the host that executes this module.
python >= 2.6
apache-libcloud >= 0.13.3, >= 0.17.0 if using JSON credentials, >= 0.20.0 if using preemptible option
Parameters
Parameter |
Comments |
---|---|
Defines whether the instance should be automatically restarted when it is terminated by Compute Engine. Choices:
|
|
Set to Choices:
|
|
path to the JSON file associated with the service account email |
|
description of instance template |
|
Indicate that the boot disk should be deleted when the Node is deleted. Choices:
|
|
Specify a Choices:
|
|
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). |
|
Support passing in the GCE-specific formatted formatted disks[] structure. Case sensitive. see https://cloud.google.com/compute/docs/reference/latest/instanceTemplates#resource for detailed information |
|
The external IP address to use. If Default: |
|
The image to use to create the instance. Cannot specify both both image and source. |
|
The image family to use to create the instance. If image has been used image_family is ignored. Cannot specify both image and source. Default: |
|
a hash/dictionary of custom data for the instance; ‘{“key”:”value”, …}’ |
|
The name of the GCE instance template. |
|
The network to associate with the instance. Default: |
|
Support passing in the GCE-specific formatted networkInterfaces[] structure. |
|
path to the pem file associated with the service account email This option is deprecated. Use ‘credentials_file’. |
|
Defines whether the instance is preemptible. Choices:
|
|
your GCE project ID |
|
service account email |
|
service account permissions (see https://cloud.google.com/sdk/gcloud/reference/compute/instances/create, –scopes section for detailed information) Available choices are: |
|
The desired machine type for the instance template. Default: |
|
A source disk to attach to the instance. Cannot specify both image and source. |
|
The desired state for the instance template. Choices:
|
|
The Subnetwork resource name for this instance. |
|
Region that subnetwork resides in. (Required for subnetwork to successfully complete) |
|
a comma-separated list of tags to associate with the instance |
Notes
Note
JSON credentials strongly preferred.
Examples
# Usage
- name: Create instance template named foo
community.google.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: "[email protected]"
# Example Playbook
- name: Compute Engine Instance Template Examples
hosts: localhost
vars:
service_account_email: "[email protected]"
credentials_file: "/path/to/your-key.json"
project_id: "your-project-name"
tasks:
- name: Create instance template
community.google.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.google.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 }}"
# Example playbook using disks_gce_struct
- name: Compute Engine Instance Template Examples
hosts: localhost
vars:
service_account_email: "[email protected]"
credentials_file: "/path/to/your-key.json"
project_id: "your-project-name"
tasks:
- name: Create instance template
community.google.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