mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -07:00
* ec2_snapshot_copy: add wait_timeout parameter
This commit is contained in:
parent
2afb1090b1
commit
1f3b480142
1 changed files with 15 additions and 1 deletions
|
@ -41,6 +41,11 @@ options:
|
||||||
- Wait for the copied Snapshot to be in 'Available' state before returning.
|
- Wait for the copied Snapshot to be in 'Available' state before returning.
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
|
wait_timeout:
|
||||||
|
version_added: "2.6"
|
||||||
|
description:
|
||||||
|
- How long before wait gives up, in seconds.
|
||||||
|
default: 600
|
||||||
tags:
|
tags:
|
||||||
description:
|
description:
|
||||||
- A hash/dictionary of tags to add to the new Snapshot; '{"key":"value"}' and '{"key":"value","key":"value"}'
|
- 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
|
region: eu-west-1
|
||||||
source_snapshot_id: snap-xxxxxxx
|
source_snapshot_id: snap-xxxxxxx
|
||||||
wait: yes
|
wait: yes
|
||||||
|
wait_timeout: 1200 # Default timeout is 600
|
||||||
register: snapshot_id
|
register: snapshot_id
|
||||||
|
|
||||||
# Tagged Snapshot copy
|
# Tagged Snapshot copy
|
||||||
|
@ -135,7 +141,14 @@ def copy_snapshot(module, ec2):
|
||||||
try:
|
try:
|
||||||
snapshot_id = ec2.copy_snapshot(**params)['SnapshotId']
|
snapshot_id = ec2.copy_snapshot(**params)['SnapshotId']
|
||||||
if module.params.get('wait'):
|
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'):
|
if module.params.get('tags'):
|
||||||
ec2.create_tags(
|
ec2.create_tags(
|
||||||
Resources=[snapshot_id],
|
Resources=[snapshot_id],
|
||||||
|
@ -159,6 +172,7 @@ def main():
|
||||||
encrypted=dict(type='bool', default=False, required=False),
|
encrypted=dict(type='bool', default=False, required=False),
|
||||||
kms_key_id=dict(type='str', required=False),
|
kms_key_id=dict(type='str', required=False),
|
||||||
wait=dict(type='bool', default=False),
|
wait=dict(type='bool', default=False),
|
||||||
|
wait_timeout=dict(type='int', default=600),
|
||||||
tags=dict(type='dict')))
|
tags=dict(type='dict')))
|
||||||
|
|
||||||
module = AnsibleModule(argument_spec=argument_spec)
|
module = AnsibleModule(argument_spec=argument_spec)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue