Skip to content

Commit

Permalink
ec2_instance should raise an error when missing permission to stop in…
Browse files Browse the repository at this point in the history
…stance and state is set to rebooted (ansible-collections#756)

ec2_instance - raise an error when missing permission to stop instance

SUMMARY


Fixes ansible-collections#671
When missing permission to stop an instance, the module quietly exists instead of raising an error.
This PR fixes that.
ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ec2_instance

Reviewed-by: Gonéri Le Bouder <[email protected]>
  • Loading branch information
abikouo authored Apr 6, 2022
1 parent cf50ab1 commit 4483fde
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- ec2_instance - raise an error when missing permission to stop instance when ``state`` is set to ``rebooted``` (https://github.com/ansible-collections/amazon.aws/pull/671).
9 changes: 8 additions & 1 deletion plugins/modules/ec2_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,13 @@ def ensure_instance_state(desired_module_state):
filters=module.params.get('filters'),
desired_module_state='stopped',
)

if failed:
module.fail_json(
msg="Unable to stop instances: {0}".format(failure_reason),
stop_success=list(_changed),
stop_failed=failed)

changed |= bool(len(_changed))
_changed, failed, instances, failure_reason = change_instance_state(
filters=module.params.get('filters'),
Expand Down Expand Up @@ -1794,7 +1801,7 @@ def handle_existing(existing_matches, state):
)

state_results = ensure_instance_state(state)

alter_config_result['changed'] |= state_results.pop('changed', False)
result = {**state_results, **alter_config_result}

return result
Expand Down

0 comments on commit 4483fde

Please sign in to comment.