diff options
author | Julien PRIGENT <julienprigent@wanadoo.fr> | 2018-04-06 01:40:16 +0100 |
---|---|---|
committer | Will Thames <will@thames.id.au> | 2018-04-06 10:40:16 +1000 |
commit | 1f3b48014274cafa5dc315fab05a45f72f534239 (patch) | |
tree | 6f13b386e654f191c9ff6657c968b2ce873d2c6e | |
parent | 2afb1090b14c88093a0a6bb0ab59e029f57eb599 (diff) | |
download | ansible-1f3b48014274cafa5dc315fab05a45f72f534239.tar.gz |
ec2_snapshot_copy: Add wait_timeout module parameter (#38072) (#38243)
* ec2_snapshot_copy: add wait_timeout parameter
-rw-r--r-- | lib/ansible/modules/cloud/amazon/ec2_snapshot_copy.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/ansible/modules/cloud/amazon/ec2_snapshot_copy.py b/lib/ansible/modules/cloud/amazon/ec2_snapshot_copy.py index f4b228adc3..b51852d6df 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_snapshot_copy.py +++ b/lib/ansible/modules/cloud/amazon/ec2_snapshot_copy.py @@ -41,6 +41,11 @@ options: - Wait for the copied Snapshot to be in 'Available' state before returning. type: bool default: 'no' + wait_timeout: + version_added: "2.6" + description: + - How long before wait gives up, in seconds. + default: 600 tags: description: - A hash/dictionary of tags to add to the new Snapshot; '{"key":"value"}' and '{"key":"value","key":"value"}' @@ -65,6 +70,7 @@ EXAMPLES = ''' region: eu-west-1 source_snapshot_id: snap-xxxxxxx wait: yes + wait_timeout: 1200 # Default timeout is 600 register: snapshot_id # Tagged Snapshot copy @@ -135,7 +141,14 @@ def copy_snapshot(module, ec2): try: snapshot_id = ec2.copy_snapshot(**params)['SnapshotId'] if module.params.get('wait'): - ec2.get_waiter('snapshot_completed').wait(SnapshotIds=[snapshot_id]) + delay = 15 + # Add one to max_attempts as wait() increment + # its counter before assessing it for time.sleep() + max_attempts = (module.params.get('wait_timeout') // delay) + 1 + ec2.get_waiter('snapshot_completed').wait( + SnapshotIds=[snapshot_id], + WaiterConfig=dict(Delay=delay, MaxAttempts=max_attempts) + ) if module.params.get('tags'): ec2.create_tags( Resources=[snapshot_id], @@ -159,6 +172,7 @@ def main(): encrypted=dict(type='bool', default=False, required=False), kms_key_id=dict(type='str', required=False), wait=dict(type='bool', default=False), + wait_timeout=dict(type='int', default=600), tags=dict(type='dict'))) module = AnsibleModule(argument_spec=argument_spec) |