mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Adds support for creating GCE persistent disks from images
This commit is contained in:
parent
1e76fe2569
commit
0b45b1256d
2 changed files with 50 additions and 1 deletions
|
@ -62,6 +62,12 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: 10
|
default: 10
|
||||||
aliases: []
|
aliases: []
|
||||||
|
image:
|
||||||
|
description:
|
||||||
|
- the source image to use for the disk
|
||||||
|
required: false
|
||||||
|
default: null
|
||||||
|
aliases: []
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- desired state of the persistent disk
|
- desired state of the persistent disk
|
||||||
|
@ -132,6 +138,7 @@ def main():
|
||||||
mode = dict(default='READ_ONLY', choices=['READ_WRITE', 'READ_ONLY']),
|
mode = dict(default='READ_ONLY', choices=['READ_WRITE', 'READ_ONLY']),
|
||||||
name = dict(required=True),
|
name = dict(required=True),
|
||||||
size_gb = dict(default=10),
|
size_gb = dict(default=10),
|
||||||
|
image = dict(),
|
||||||
state = dict(default='present'),
|
state = dict(default='present'),
|
||||||
zone = dict(default='us-central1-b'),
|
zone = dict(default='us-central1-b'),
|
||||||
service_account_email = dict(),
|
service_account_email = dict(),
|
||||||
|
@ -147,6 +154,7 @@ def main():
|
||||||
mode = module.params.get('mode')
|
mode = module.params.get('mode')
|
||||||
name = module.params.get('name')
|
name = module.params.get('name')
|
||||||
size_gb = module.params.get('size_gb')
|
size_gb = module.params.get('size_gb')
|
||||||
|
image = module.params.get('image')
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
zone = module.params.get('zone')
|
zone = module.params.get('zone')
|
||||||
|
|
||||||
|
@ -204,8 +212,11 @@ def main():
|
||||||
instance_name, zone), changed=False)
|
instance_name, zone), changed=False)
|
||||||
|
|
||||||
if not disk:
|
if not disk:
|
||||||
|
lc_image = None
|
||||||
|
if image is not None:
|
||||||
|
lc_image = gce.ex_get_image(image)
|
||||||
try:
|
try:
|
||||||
disk = gce.create_volume(size_gb, name, location=zone)
|
disk = gce.create_volume(size_gb, name, location=zone, image=lc_image)
|
||||||
except ResourceExistsError:
|
except ResourceExistsError:
|
||||||
pass
|
pass
|
||||||
except QuotaExceededError:
|
except QuotaExceededError:
|
||||||
|
@ -214,6 +225,7 @@ def main():
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||||
json_output['size_gb'] = size_gb
|
json_output['size_gb'] = size_gb
|
||||||
|
json_output['image'] = image
|
||||||
changed = True
|
changed = True
|
||||||
if inst and not is_attached:
|
if inst and not is_attached:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -124,3 +124,40 @@
|
||||||
- 'result.changed'
|
- 'result.changed'
|
||||||
- 'result.name == "{{ instance_name }}"'
|
- 'result.name == "{{ instance_name }}"'
|
||||||
- 'result.state == "absent"'
|
- 'result.state == "absent"'
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
- name: test image given (state=present)
|
||||||
|
gce_pd:
|
||||||
|
name: "{{ instance_name }}"
|
||||||
|
image: debian-7
|
||||||
|
service_account_email: "{{ service_account_email }}"
|
||||||
|
pem_file: "{{ pem_file }}"
|
||||||
|
project_id: "{{ project_id }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert image given (state=present)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed'
|
||||||
|
- 'result.name == "{{ instance_name }}"'
|
||||||
|
- 'result.image == "debian-7"'
|
||||||
|
- 'result.state == "present"'
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
- name: test image given (state=absent)
|
||||||
|
gce_pd:
|
||||||
|
name: "{{ instance_name }}"
|
||||||
|
image: debian-7
|
||||||
|
service_account_email: "{{ service_account_email }}"
|
||||||
|
pem_file: "{{ pem_file }}"
|
||||||
|
project_id: "{{ project_id }}"
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert image given (state=absent)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'result.changed'
|
||||||
|
- 'result.name == "{{ instance_name }}"'
|
||||||
|
- 'result.state == "absent"'
|
||||||
|
|
Loading…
Reference in a new issue