From c22ec81b9926375dba65879285530d58f654984f Mon Sep 17 00:00:00 2001 From: evancarter-iex Date: Wed, 12 Jul 2017 16:36:05 -0400 Subject: [PATCH] gce_instance_template: Add ability to use disks_gce_struct (#25500) * Add ability to use disks_gce_struct * Fixed typos in the options section * Spacing fixes --- .../cloud/google/gce_instance_template.py | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/google/gce_instance_template.py b/lib/ansible/modules/cloud/google/gce_instance_template.py index 74e95e341af..95d0755875f 100644 --- a/lib/ansible/modules/cloud/google/gce_instance_template.py +++ b/lib/ansible/modules/cloud/google/gce_instance_template.py @@ -140,6 +140,13 @@ options: - Support passing in the GCE-specific formatted networkInterfaces[] structure. default: null + 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 + default: null + version_added: "2.4" project_id: description: - your GCE project ID @@ -205,6 +212,32 @@ EXAMPLES = ''' 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: "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 + ''' RETURN = ''' @@ -234,7 +267,6 @@ except ImportError: def get_info(inst): """Retrieves instance template information - """ return({ 'name': inst.name, @@ -272,6 +304,7 @@ def create_instance_template(module, gce): metadata = module.params.get('metadata') description = module.params.get('description') disks = module.params.get('disks') + disks_gce_struct = module.params.get('disks_gce_struct') changed = False # args of ex_create_instancetemplate @@ -360,6 +393,9 @@ def create_instance_template(module, gce): if tags is not None: gce_args['tags'] = tags + if disks_gce_struct is not None: + gce_args['disks_gce_struct'] = disks_gce_struct + # Try to convert the user's metadata value into the format expected # by GCE. First try to ensure user has proper quoting of a # dictionary-like syntax using 'literal_eval', then convert the python @@ -534,7 +570,8 @@ def main(): project_id=dict(), pem_file=dict(type='path'), credentials_file=dict(type='path'), - subnetwork_region=dict() + subnetwork_region=dict(), + disks_gce_struct=dict(type='list') ), mutually_exclusive=[['source', 'image']], required_one_of=[['image', 'image_family']],