-
Notifications
You must be signed in to change notification settings - Fork 341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add wait_for_modify_volume_complete option #1558
base: main
Are you sure you want to change the base?
Changes from all commits
e6767df
7bb7ac8
6d28b3c
d48dcf9
30bd554
d0be10e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- ec2_vol - added ``wait`` and ``wait_timeout`` options (https://github.com/ansible-collections/amazon.aws/pull/1558). |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,18 @@ | |
- If set, allows to create volume in an Outpost. | ||
type: str | ||
version_added: 3.1.0 | ||
wait: | ||
description: | ||
- Wait for volume modification to complete. | ||
type: bool | ||
default: false | ||
version_added: 6.3.0 | ||
wait_timeout: | ||
description: | ||
- How long before wait gives up, in seconds. | ||
type: int | ||
default: 900 | ||
version_added: 6.3.0 | ||
author: | ||
- "Lester Wade (@lwade)" | ||
notes: | ||
|
@@ -439,6 +451,26 @@ def update_volume(module, ec2_conn, volume): | |
volume["multi_attach_enabled"] = response.get("VolumeModification").get("TargetMultiAttachEnabled") | ||
volume["throughput"] = response.get("VolumeModification").get("TargetThroughput") | ||
|
||
if module.params.get("wait"): | ||
mod_state = "" | ||
_wait_till = module.params.get("wait_timeout") + time.time() | ||
while _wait_till > time.time(): | ||
mod_response = ec2_conn.describe_volumes_modifications(VolumeIds=[volume["volume_id"]]) | ||
mod_state = mod_response.get("VolumesModifications")[0].get("ModificationState") | ||
|
||
if mod_state == "completed": | ||
break | ||
|
||
if mod_state == "failed": | ||
module.fail_json(msg=f"Volume {volume['volume_id']} modification has failed.") | ||
|
||
time.sleep(30) | ||
|
||
else: | ||
module.fail_json( | ||
msg=f"Volume {volume['volume_id']} modification state has not reached 'completed' after {module.params.get('wait_timeout')} seconds." | ||
) | ||
|
||
return volume, changed | ||
|
||
|
||
|
@@ -714,6 +746,8 @@ def main(): | |
outpost_arn=dict(type="str"), | ||
purge_tags=dict(type="bool", default=True), | ||
multi_attach=dict(type="bool"), | ||
wait=dict(default=False, type="bool"), | ||
wait_timeout=dict(type="int", default=900), | ||
) | ||
|
||
module = AnsibleAWSModule( | ||
|
@@ -738,6 +772,8 @@ def main(): | |
volume_type = module.params.get("volume_type") | ||
throughput = module.params.get("throughput") | ||
multi_attach = module.params.get("multi_attach") | ||
modify_volume = module.params.get("modify_volume") | ||
wait = module.params.get("wait") | ||
|
||
# Ensure we have the zone or can get the zone | ||
if instance is None and zone is None and state == "present": | ||
|
@@ -769,6 +805,9 @@ def main(): | |
if multi_attach is True and volume_type not in ("io1", "io2"): | ||
module.fail_json(msg="multi_attach is only supported for io1 and io2 volumes.") | ||
|
||
if wait is True and modify_volume is False: | ||
module.fail_json(msg="wait does nothing if modify_volume is False.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it should work for now. We would probably also like to add the option to wait for deletion in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are using this module currently and have decided to wait for either How about having an option like this? wait_modification_states:
description:
- A list of modification states to wait for. Valid options are "completed" and "optimizing"
type: list
default: ["completed", "optimizing"] |
||
|
||
# Set changed flag | ||
changed = False | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small thing. I guess we should enclose mod_response = ec2_conn.describe_volumes_modifications(VolumeIds=[volume["volume_id"]]) in a try-except block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I can add that