ec2_snapshot: Add wait' and snapshot_tags' parameters, return more

info on success
This commit is contained in:
Hagai 2014-03-04 21:37:15 +02:00
parent 21054798a5
commit c900254ed0

View file

@ -124,6 +124,8 @@ def main():
ec2_url = dict(), ec2_url = dict(),
ec2_secret_key = dict(aliases=['aws_secret_key', 'secret_key'], no_log=True), ec2_secret_key = dict(aliases=['aws_secret_key', 'secret_key'], no_log=True),
ec2_access_key = dict(aliases=['aws_access_key', 'access_key']), ec2_access_key = dict(aliases=['aws_access_key', 'access_key']),
wait = dict(choices=BOOLEANS, default='true'),
snapshot_tags = dict(type='dict', default=dict()),
) )
) )
@ -131,6 +133,8 @@ def main():
description = module.params.get('description') description = module.params.get('description')
instance_id = module.params.get('instance_id') instance_id = module.params.get('instance_id')
device_name = module.params.get('device_name') device_name = module.params.get('device_name')
wait = module.params.get('wait')
snapshot_tags = module.params.get('snapshot_tags')
if not volume_id and not instance_id or volume_id and instance_id: if not volume_id and not instance_id or volume_id and instance_id:
module.fail_json('One and only one of volume_id or instance_id must be specified') module.fail_json('One and only one of volume_id or instance_id must be specified')
@ -150,10 +154,18 @@ def main():
try: try:
snapshot = ec2.create_snapshot(volume_id, description=description) snapshot = ec2.create_snapshot(volume_id, description=description)
if wait:
snapshot.update()
while snapshot.status != 'completed':
time.sleep(3)
snapshot.update()
for k, v in snapshot_tags.items():
snapshot.add_tag(k, v)
except boto.exception.BotoServerError, e: except boto.exception.BotoServerError, e:
module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message)) module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message))
module.exit_json(changed=True, snapshot_id=snapshot.id) module.exit_json(changed=True, snapshot_id=snapshot.id, volume_id=snapshot.volume_id,
volume_size=snapshot.volume_size, tags=snapshot.tags.copy())
# import module snippets # import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *