2013-07-02 20:24:40 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: ec2_ami
|
2013-11-19 00:55:49 +01:00
|
|
|
version_added: "1.3"
|
2014-12-01 21:14:57 +01:00
|
|
|
short_description: create or destroy an image in ec2
|
2013-07-02 20:24:40 +02:00
|
|
|
description:
|
2015-05-01 15:57:48 +02:00
|
|
|
- Creates or deletes ec2 images.
|
2013-07-02 20:24:40 +02:00
|
|
|
options:
|
|
|
|
instance_id:
|
|
|
|
description:
|
|
|
|
- instance id of the image to create
|
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- The name of the new image to create
|
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
wait:
|
|
|
|
description:
|
2013-07-03 19:35:32 +02:00
|
|
|
- wait for the AMI to be in state 'available' before returning.
|
2013-07-02 20:24:40 +02:00
|
|
|
required: false
|
|
|
|
default: "no"
|
|
|
|
choices: [ "yes", "no" ]
|
|
|
|
wait_timeout:
|
|
|
|
description:
|
|
|
|
- how long before wait gives up, in seconds
|
|
|
|
default: 300
|
|
|
|
state:
|
|
|
|
description:
|
|
|
|
- create or deregister/delete image
|
|
|
|
required: false
|
|
|
|
default: 'present'
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- An optional human-readable string describing the contents and purpose of the AMI.
|
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
no_reboot:
|
|
|
|
description:
|
2013-12-13 00:03:00 +01:00
|
|
|
- An optional flag indicating that the bundling process should not attempt to shutdown the instance before bundling. If this flag is True, the responsibility of maintaining file system integrity is left to the owner of the instance. The default choice is "no".
|
2013-07-02 20:24:40 +02:00
|
|
|
required: false
|
2013-12-13 00:03:00 +01:00
|
|
|
default: no
|
2013-07-02 20:24:40 +02:00
|
|
|
choices: [ "yes", "no" ]
|
|
|
|
image_id:
|
|
|
|
description:
|
|
|
|
- Image ID to be deregistered.
|
|
|
|
required: false
|
|
|
|
default: null
|
2014-12-01 17:51:48 +01:00
|
|
|
device_mapping:
|
2015-06-12 16:39:47 +02:00
|
|
|
version_added: "2.0"
|
2014-12-01 17:51:48 +01:00
|
|
|
description:
|
2015-09-24 14:37:03 +02:00
|
|
|
- An optional list of device hashes/dictionaries with custom configurations (same block-device-mapping parameters)
|
2015-09-28 17:22:36 +02:00
|
|
|
- "Valid properties include: device_name, volume_type, size (in GB), delete_on_termination (boolean), no_device (boolean), snapshot_id, iops (for io1 volume_type)"
|
2014-12-01 17:51:48 +01:00
|
|
|
required: false
|
|
|
|
default: null
|
2013-07-02 20:24:40 +02:00
|
|
|
delete_snapshot:
|
|
|
|
description:
|
2014-12-12 20:29:51 +01:00
|
|
|
- Whether or not to delete an AMI while deregistering it.
|
2013-07-02 20:24:40 +02:00
|
|
|
required: false
|
|
|
|
default: null
|
2015-03-19 16:39:42 +01:00
|
|
|
tags:
|
|
|
|
description:
|
|
|
|
- a hash/dictionary of tags to add to the new image; '{"key":"value"}' and '{"key":"value","key":"value"}'
|
|
|
|
required: false
|
|
|
|
default: null
|
2015-05-01 15:57:48 +02:00
|
|
|
version_added: "2.0"
|
2014-12-17 17:30:05 +01:00
|
|
|
launch_permissions:
|
|
|
|
description:
|
|
|
|
- Users and groups that should be able to launch the ami. Expects dictionary with a key of user_ids and/or group_names. user_ids should be a list of account ids. group_name should be a list of groups, "all" is the only acceptable value currently.
|
|
|
|
required: false
|
|
|
|
default: null
|
2015-11-03 19:25:46 +01:00
|
|
|
version_added: "2.0"
|
2015-06-15 20:41:22 +02:00
|
|
|
author: "Evan Duffield (@scicoin-project) <eduffield@iacquire.com>"
|
2015-10-07 22:16:24 +02:00
|
|
|
extends_documentation_fragment:
|
|
|
|
- aws
|
|
|
|
- ec2
|
2013-07-02 20:24:40 +02:00
|
|
|
'''
|
|
|
|
|
2013-07-21 17:15:06 +02:00
|
|
|
# Thank you to iAcquire for sponsoring development of this module.
|
|
|
|
|
2013-07-02 20:24:40 +02:00
|
|
|
EXAMPLES = '''
|
|
|
|
# Basic AMI Creation
|
2014-12-01 21:14:57 +01:00
|
|
|
- ec2_ami:
|
2013-08-13 15:30:56 +02:00
|
|
|
aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
2013-07-02 20:24:40 +02:00
|
|
|
instance_id: i-xxxxxx
|
|
|
|
wait: yes
|
|
|
|
name: newtest
|
2015-03-19 16:39:42 +01:00
|
|
|
tags:
|
|
|
|
Name: newtest
|
|
|
|
Service: TestService
|
2013-07-02 20:24:40 +02:00
|
|
|
register: instance
|
|
|
|
|
|
|
|
# Basic AMI Creation, without waiting
|
2014-12-01 21:14:57 +01:00
|
|
|
- ec2_ami:
|
2013-08-13 15:30:56 +02:00
|
|
|
aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
region: xxxxxx
|
2013-07-02 20:24:40 +02:00
|
|
|
instance_id: i-xxxxxx
|
|
|
|
wait: no
|
|
|
|
name: newtest
|
|
|
|
register: instance
|
|
|
|
|
2014-12-01 17:51:48 +01:00
|
|
|
# AMI Creation, with a custom root-device size and another EBS attached
|
|
|
|
- ec2_ami
|
|
|
|
aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
instance_id: i-xxxxxx
|
|
|
|
name: newtest
|
|
|
|
device_mapping:
|
|
|
|
- device_name: /dev/sda1
|
|
|
|
size: XXX
|
|
|
|
delete_on_termination: true
|
|
|
|
volume_type: gp2
|
|
|
|
- device_name: /dev/sdb
|
|
|
|
size: YYY
|
|
|
|
delete_on_termination: false
|
|
|
|
volume_type: gp2
|
|
|
|
register: instance
|
|
|
|
|
2015-09-24 14:37:03 +02:00
|
|
|
# AMI Creation, excluding a volume attached at /dev/sdb
|
|
|
|
- ec2_ami
|
|
|
|
aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
instance_id: i-xxxxxx
|
|
|
|
name: newtest
|
|
|
|
device_mapping:
|
|
|
|
- device_name: /dev/sda1
|
|
|
|
size: XXX
|
|
|
|
delete_on_termination: true
|
|
|
|
volume_type: gp2
|
|
|
|
- device_name: /dev/sdb
|
|
|
|
no_device: yes
|
|
|
|
register: instance
|
|
|
|
|
2013-07-02 20:24:40 +02:00
|
|
|
# Deregister/Delete AMI
|
2014-12-01 21:14:57 +01:00
|
|
|
- ec2_ami:
|
2013-08-13 15:30:56 +02:00
|
|
|
aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
region: xxxxxx
|
2014-12-01 21:14:57 +01:00
|
|
|
image_id: "{{ instance.image_id }}"
|
2013-07-02 20:24:40 +02:00
|
|
|
delete_snapshot: True
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
# Deregister AMI
|
2014-12-01 21:14:57 +01:00
|
|
|
- ec2_ami:
|
2013-08-13 15:30:56 +02:00
|
|
|
aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
region: xxxxxx
|
2014-12-01 21:14:57 +01:00
|
|
|
image_id: "{{ instance.image_id }}"
|
2013-07-02 20:24:40 +02:00
|
|
|
delete_snapshot: False
|
|
|
|
state: absent
|
|
|
|
|
2014-12-17 17:30:05 +01:00
|
|
|
# Update AMI Launch Permissions, making it public
|
|
|
|
- ec2_ami:
|
|
|
|
aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
region: xxxxxx
|
|
|
|
image_id: "{{ instance.image_id }}"
|
|
|
|
state: present
|
|
|
|
launch_permissions:
|
|
|
|
group_names: ['all']
|
|
|
|
|
|
|
|
# Allow AMI to be launched by another account
|
|
|
|
- ec2_ami:
|
|
|
|
aws_access_key: xxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
region: xxxxxx
|
|
|
|
image_id: "{{ instance.image_id }}"
|
|
|
|
state: present
|
|
|
|
launch_permissions:
|
|
|
|
user_ids: ['123456789012']
|
2013-07-02 20:24:40 +02:00
|
|
|
'''
|
2015-04-02 01:16:54 +02:00
|
|
|
|
2013-07-02 20:24:40 +02:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
try:
|
2013-10-04 06:05:50 +02:00
|
|
|
import boto
|
2013-07-02 20:24:40 +02:00
|
|
|
import boto.ec2
|
2014-12-01 17:06:20 +01:00
|
|
|
from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping
|
2015-04-02 01:16:54 +02:00
|
|
|
HAS_BOTO = True
|
2013-07-02 20:24:40 +02:00
|
|
|
except ImportError:
|
2015-04-02 01:16:54 +02:00
|
|
|
HAS_BOTO = False
|
|
|
|
|
2013-07-02 20:24:40 +02:00
|
|
|
|
|
|
|
def create_image(module, ec2):
|
|
|
|
"""
|
2013-07-03 19:35:32 +02:00
|
|
|
Creates new AMI
|
2013-07-02 20:24:40 +02:00
|
|
|
|
2013-08-22 02:13:05 +02:00
|
|
|
module : AnsibleModule object
|
2013-07-02 20:24:40 +02:00
|
|
|
ec2: authenticated ec2 connection object
|
|
|
|
"""
|
|
|
|
|
|
|
|
instance_id = module.params.get('instance_id')
|
|
|
|
name = module.params.get('name')
|
|
|
|
wait = module.params.get('wait')
|
|
|
|
wait_timeout = int(module.params.get('wait_timeout'))
|
|
|
|
description = module.params.get('description')
|
|
|
|
no_reboot = module.params.get('no_reboot')
|
2014-12-01 17:06:20 +01:00
|
|
|
device_mapping = module.params.get('device_mapping')
|
2015-03-19 16:39:42 +01:00
|
|
|
tags = module.params.get('tags')
|
2014-12-17 17:30:05 +01:00
|
|
|
launch_permissions = module.params.get('launch_permissions')
|
2013-07-02 20:24:40 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
params = {'instance_id': instance_id,
|
|
|
|
'name': name,
|
|
|
|
'description': description,
|
|
|
|
'no_reboot': no_reboot}
|
|
|
|
|
2014-12-01 17:06:20 +01:00
|
|
|
if device_mapping:
|
|
|
|
bdm = BlockDeviceMapping()
|
|
|
|
for device in device_mapping:
|
|
|
|
if 'device_name' not in device:
|
|
|
|
module.fail_json(msg = 'Device name must be set for volume')
|
|
|
|
device_name = device['device_name']
|
|
|
|
del device['device_name']
|
|
|
|
bd = BlockDeviceType(**device)
|
|
|
|
bdm[device_name] = bd
|
|
|
|
params['block_device_mapping'] = bdm
|
|
|
|
|
2013-07-02 20:24:40 +02:00
|
|
|
image_id = ec2.create_image(**params)
|
|
|
|
except boto.exception.BotoServerError, e:
|
2015-01-31 09:42:49 +01:00
|
|
|
if e.error_code == 'InvalidAMIName.Duplicate':
|
|
|
|
images = ec2.get_all_images()
|
|
|
|
for img in images:
|
|
|
|
if img.name == name:
|
|
|
|
module.exit_json(msg="AMI name already present", image_id=img.id, state=img.state, changed=False)
|
|
|
|
else:
|
|
|
|
module.fail_json(msg="Error in retrieving duplicate AMI details")
|
|
|
|
else:
|
|
|
|
module.fail_json(msg="%s: %s" % (e.error_code, e.error_message))
|
2013-07-02 20:24:40 +02:00
|
|
|
|
2013-10-04 06:05:50 +02:00
|
|
|
# Wait until the image is recognized. EC2 API has eventual consistency,
|
|
|
|
# such that a successful CreateImage API call doesn't guarantee the success
|
|
|
|
# of subsequent DescribeImages API call using the new image id returned.
|
2014-02-26 20:31:17 +01:00
|
|
|
for i in range(wait_timeout):
|
2013-10-04 06:05:50 +02:00
|
|
|
try:
|
|
|
|
img = ec2.get_image(image_id)
|
|
|
|
break
|
2014-02-02 18:33:27 +01:00
|
|
|
except boto.exception.EC2ResponseError, e:
|
2014-02-26 20:31:17 +01:00
|
|
|
if 'InvalidAMIID.NotFound' in e.error_code and wait:
|
2013-10-04 06:05:50 +02:00
|
|
|
time.sleep(1)
|
|
|
|
else:
|
2014-02-26 20:31:17 +01:00
|
|
|
module.fail_json(msg="Error while trying to find the new image. Using wait=yes and/or a longer wait_timeout may help.")
|
2013-10-04 06:05:50 +02:00
|
|
|
else:
|
2014-02-26 20:31:17 +01:00
|
|
|
module.fail_json(msg="timed out waiting for image to be recognized")
|
2013-10-04 06:05:50 +02:00
|
|
|
|
|
|
|
# wait here until the image is created
|
2013-07-02 20:24:40 +02:00
|
|
|
wait_timeout = time.time() + wait_timeout
|
2013-07-03 19:35:32 +02:00
|
|
|
while wait and wait_timeout > time.time() and (img is None or img.state != 'available'):
|
2013-07-02 20:24:40 +02:00
|
|
|
img = ec2.get_image(image_id)
|
|
|
|
time.sleep(3)
|
|
|
|
if wait and wait_timeout <= time.time():
|
|
|
|
# waiting took too long
|
|
|
|
module.fail_json(msg = "timed out waiting for image to be created")
|
|
|
|
|
2015-03-19 16:39:42 +01:00
|
|
|
if tags:
|
|
|
|
try:
|
|
|
|
ec2.create_tags(image_id, tags)
|
|
|
|
except boto.exception.EC2ResponseError, e:
|
|
|
|
module.fail_json(msg = "Image tagging failed => %s: %s" % (e.error_code, e.error_message))
|
2014-12-17 17:30:05 +01:00
|
|
|
if launch_permissions:
|
|
|
|
try:
|
|
|
|
img = ec2.get_image(image_id)
|
|
|
|
img.set_launch_permissions(**launch_permissions)
|
|
|
|
except boto.exception.BotoServerError, e:
|
|
|
|
module.fail_json(msg="%s: %s" % (e.error_code, e.error_message), image_id=image_id)
|
2015-03-19 16:39:42 +01:00
|
|
|
|
2013-07-02 20:24:40 +02:00
|
|
|
module.exit_json(msg="AMI creation operation complete", image_id=image_id, state=img.state, changed=True)
|
|
|
|
|
|
|
|
|
|
|
|
def deregister_image(module, ec2):
|
|
|
|
"""
|
|
|
|
Deregisters AMI
|
|
|
|
"""
|
|
|
|
|
|
|
|
image_id = module.params.get('image_id')
|
|
|
|
delete_snapshot = module.params.get('delete_snapshot')
|
|
|
|
wait = module.params.get('wait')
|
|
|
|
wait_timeout = int(module.params.get('wait_timeout'))
|
|
|
|
|
|
|
|
img = ec2.get_image(image_id)
|
|
|
|
if img == None:
|
2013-07-03 19:35:32 +02:00
|
|
|
module.fail_json(msg = "Image %s does not exist" % image_id, changed=False)
|
2013-07-02 20:24:40 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
params = {'image_id': image_id,
|
|
|
|
'delete_snapshot': delete_snapshot}
|
|
|
|
|
|
|
|
res = ec2.deregister_image(**params)
|
|
|
|
except boto.exception.BotoServerError, e:
|
|
|
|
module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message))
|
|
|
|
|
|
|
|
# wait here until the image is gone
|
|
|
|
img = ec2.get_image(image_id)
|
|
|
|
wait_timeout = time.time() + wait_timeout
|
2013-07-03 19:35:32 +02:00
|
|
|
while wait and wait_timeout > time.time() and img is not None:
|
2013-07-02 20:24:40 +02:00
|
|
|
img = ec2.get_image(image_id)
|
|
|
|
time.sleep(3)
|
|
|
|
if wait and wait_timeout <= time.time():
|
|
|
|
# waiting took too long
|
|
|
|
module.fail_json(msg = "timed out waiting for image to be reregistered/deleted")
|
|
|
|
|
|
|
|
module.exit_json(msg="AMI deregister/delete operation complete", changed=True)
|
|
|
|
|
2015-04-02 01:16:54 +02:00
|
|
|
|
2014-12-17 17:30:05 +01:00
|
|
|
def update_image(module, ec2):
|
|
|
|
"""
|
|
|
|
Updates AMI
|
|
|
|
"""
|
|
|
|
|
|
|
|
image_id = module.params.get('image_id')
|
|
|
|
launch_permissions = module.params.get('launch_permissions')
|
|
|
|
if 'user_ids' in launch_permissions:
|
|
|
|
launch_permissions['user_ids'] = [str(user_id) for user_id in launch_permissions['user_ids']]
|
|
|
|
|
|
|
|
img = ec2.get_image(image_id)
|
|
|
|
if img == None:
|
|
|
|
module.fail_json(msg = "Image %s does not exist" % image_id, changed=False)
|
|
|
|
|
|
|
|
try:
|
|
|
|
set_permissions = img.get_launch_permissions()
|
|
|
|
if set_permissions != launch_permissions:
|
|
|
|
if ('user_ids' in launch_permissions and launch_permissions['user_ids']) or ('group_names' in launch_permissions and launch_permissions['group_names']):
|
|
|
|
res = img.set_launch_permissions(**launch_permissions)
|
|
|
|
elif ('user_ids' in set_permissions and set_permissions['user_ids']) or ('group_names' in set_permissions and set_permissions['group_names']):
|
|
|
|
res = img.remove_launch_permissions(**set_permissions)
|
|
|
|
else:
|
|
|
|
module.exit_json(msg="AMI not updated", launch_permissions=set_permissions, changed=False)
|
|
|
|
module.exit_json(msg="AMI launch permissions updated", launch_permissions=launch_permissions, set_perms=set_permissions, changed=True)
|
|
|
|
else:
|
|
|
|
module.exit_json(msg="AMI not updated", launch_permissions=set_permissions, changed=False)
|
|
|
|
|
|
|
|
except boto.exception.BotoServerError, e:
|
|
|
|
module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message))
|
|
|
|
|
2013-07-02 20:24:40 +02:00
|
|
|
def main():
|
2014-02-05 12:11:06 +01:00
|
|
|
argument_spec = ec2_argument_spec()
|
|
|
|
argument_spec.update(dict(
|
2013-07-02 20:24:40 +02:00
|
|
|
instance_id = dict(),
|
|
|
|
image_id = dict(),
|
|
|
|
delete_snapshot = dict(),
|
|
|
|
name = dict(),
|
|
|
|
wait = dict(type="bool", default=False),
|
2013-07-03 20:10:39 +02:00
|
|
|
wait_timeout = dict(default=900),
|
2013-07-02 20:24:40 +02:00
|
|
|
description = dict(default=""),
|
2013-12-12 23:49:24 +01:00
|
|
|
no_reboot = dict(default=False, type="bool"),
|
2013-07-08 18:24:18 +02:00
|
|
|
state = dict(default='present'),
|
2014-12-01 17:06:20 +01:00
|
|
|
device_mapping = dict(type='list'),
|
2014-12-17 17:30:05 +01:00
|
|
|
tags = dict(type='dict'),
|
|
|
|
launch_permissions = dict(type='dict')
|
2013-07-02 20:24:40 +02:00
|
|
|
)
|
|
|
|
)
|
2014-02-05 12:11:06 +01:00
|
|
|
module = AnsibleModule(argument_spec=argument_spec)
|
2013-07-02 20:24:40 +02:00
|
|
|
|
2015-04-02 01:16:54 +02:00
|
|
|
if not HAS_BOTO:
|
|
|
|
module.fail_json(msg='boto required for this module')
|
|
|
|
|
2015-02-20 15:28:11 +01:00
|
|
|
try:
|
|
|
|
ec2 = ec2_connect(module)
|
|
|
|
except Exception, e:
|
2016-03-16 16:06:22 +01:00
|
|
|
module.fail_json(msg="Error while connecting to aws: %s" % str(e))
|
2013-07-02 20:24:40 +02:00
|
|
|
|
|
|
|
if module.params.get('state') == 'absent':
|
|
|
|
if not module.params.get('image_id'):
|
|
|
|
module.fail_json(msg='image_id needs to be an ami image to registered/delete')
|
|
|
|
|
|
|
|
deregister_image(module, ec2)
|
|
|
|
|
|
|
|
elif module.params.get('state') == 'present':
|
2014-12-17 17:30:05 +01:00
|
|
|
if module.params.get('image_id') and module.params.get('launch_permissions'):
|
|
|
|
# Update image's launch permissions
|
|
|
|
update_image(module, ec2)
|
|
|
|
|
2013-07-03 19:35:32 +02:00
|
|
|
# Changed is always set to true when provisioning new AMI
|
2013-07-02 20:24:40 +02:00
|
|
|
if not module.params.get('instance_id'):
|
|
|
|
module.fail_json(msg='instance_id parameter is required for new image')
|
|
|
|
if not module.params.get('name'):
|
|
|
|
module.fail_json(msg='name parameter is required for new image')
|
|
|
|
create_image(module, ec2)
|
|
|
|
|
|
|
|
|
2013-11-01 16:59:24 +01:00
|
|
|
# import module snippets
|
|
|
|
from ansible.module_utils.basic import *
|
|
|
|
from ansible.module_utils.ec2 import *
|
2013-07-02 20:24:40 +02:00
|
|
|
|
|
|
|
main()
|