|
|
@ -38,6 +38,12 @@ options:
|
|
|
|
- an optional description
|
|
|
|
- an optional description
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
default: null
|
|
|
|
|
|
|
|
family:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- an optional family name
|
|
|
|
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: null
|
|
|
|
|
|
|
|
version_added: "2.2"
|
|
|
|
source:
|
|
|
|
source:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- the source disk or the Google Cloud Storage URI to create the image from
|
|
|
|
- the source disk or the Google Cloud Storage URI to create the image from
|
|
|
@ -108,6 +114,7 @@ EXAMPLES = '''
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|
|
|
|
import libcloud
|
|
|
|
from libcloud.compute.types import Provider
|
|
|
|
from libcloud.compute.types import Provider
|
|
|
|
from libcloud.compute.providers import get_driver
|
|
|
|
from libcloud.compute.providers import get_driver
|
|
|
|
from libcloud.common.google import GoogleBaseError
|
|
|
|
from libcloud.common.google import GoogleBaseError
|
|
|
@ -128,6 +135,7 @@ def create_image(gce, name, module):
|
|
|
|
zone = module.params.get('zone')
|
|
|
|
zone = module.params.get('zone')
|
|
|
|
desc = module.params.get('description')
|
|
|
|
desc = module.params.get('description')
|
|
|
|
timeout = module.params.get('timeout')
|
|
|
|
timeout = module.params.get('timeout')
|
|
|
|
|
|
|
|
family = module.params.get('family')
|
|
|
|
|
|
|
|
|
|
|
|
if not source:
|
|
|
|
if not source:
|
|
|
|
module.fail_json(msg='Must supply a source', changed=False)
|
|
|
|
module.fail_json(msg='Must supply a source', changed=False)
|
|
|
@ -147,10 +155,14 @@ def create_image(gce, name, module):
|
|
|
|
except GoogleBaseError, e:
|
|
|
|
except GoogleBaseError, e:
|
|
|
|
module.fail_json(msg=str(e), changed=False)
|
|
|
|
module.fail_json(msg=str(e), changed=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gce_extra_args = {}
|
|
|
|
|
|
|
|
if family is not None:
|
|
|
|
|
|
|
|
gce_extra_args['family'] = family
|
|
|
|
|
|
|
|
|
|
|
|
old_timeout = gce.connection.timeout
|
|
|
|
old_timeout = gce.connection.timeout
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
gce.connection.timeout = timeout
|
|
|
|
gce.connection.timeout = timeout
|
|
|
|
gce.ex_create_image(name, volume, desc, False)
|
|
|
|
gce.ex_create_image(name, volume, desc, use_existing=False, **gce_extra_args)
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
except ResourceExistsError:
|
|
|
|
except ResourceExistsError:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
@ -175,6 +187,7 @@ def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=dict(
|
|
|
|
argument_spec=dict(
|
|
|
|
name=dict(required=True),
|
|
|
|
name=dict(required=True),
|
|
|
|
|
|
|
|
family=dict(),
|
|
|
|
description=dict(),
|
|
|
|
description=dict(),
|
|
|
|
source=dict(),
|
|
|
|
source=dict(),
|
|
|
|
state=dict(default='present', choices=['present', 'absent']),
|
|
|
|
state=dict(default='present', choices=['present', 'absent']),
|
|
|
@ -193,8 +206,13 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
name = module.params.get('name')
|
|
|
|
name = module.params.get('name')
|
|
|
|
state = module.params.get('state')
|
|
|
|
state = module.params.get('state')
|
|
|
|
|
|
|
|
family = module.params.get('family')
|
|
|
|
changed = False
|
|
|
|
changed = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if family is not None and hasattr(libcloud, '__version__') and libcloud.__version__ <= '0.20.1':
|
|
|
|
|
|
|
|
module.fail_json(msg="Apache Libcloud 1.0.0+ is required to use 'family' option",
|
|
|
|
|
|
|
|
changed=False)
|
|
|
|
|
|
|
|
|
|
|
|
# user wants to create an image.
|
|
|
|
# user wants to create an image.
|
|
|
|
if state == 'present':
|
|
|
|
if state == 'present':
|
|
|
|
changed = create_image(gce, name, module)
|
|
|
|
changed = create_image(gce, name, module)
|
|
|
|