diff --git a/changelogs/fragments/237_replace_inverse_ec2_aws_filter.yaml b/changelogs/fragments/237_replace_inverse_ec2_aws_filter.yaml new file mode 100644 index 00000000000..5f1b32d81d3 --- /dev/null +++ b/changelogs/fragments/237_replace_inverse_ec2_aws_filter.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: +- aws_ec2 module - Replace inverse aws instance-state-name filters !terminated, !shutting-down in favor of postive filters pending, running, stopping, stopped. Issue 235. (https://github.com/ansible-collections/amazon.aws/pull/237) diff --git a/plugins/modules/ec2.py b/plugins/modules/ec2.py index 40adad7f52d..990a7e69be5 100644 --- a/plugins/modules/ec2.py +++ b/plugins/modules/ec2.py @@ -1416,7 +1416,7 @@ def startstop_instances(module, ec2, instance_ids, state, instance_tags): for key, value in instance_tags.items(): filters["tag:" + key] = value - filters['instance-state-name'] = ["!terminated", "!shutting-down"] + filters['instance-state-name'] = ["pending", "running", "stopping", "stopped"] if module.params.get('id'): filters['client-token'] = module.params['id'] diff --git a/tests/integration/targets/ec2/tasks/main.yml b/tests/integration/targets/ec2/tasks/main.yml index b0ff9bf01e8..624ddbb7aea 100644 --- a/tests/integration/targets/ec2/tasks/main.yml +++ b/tests/integration/targets/ec2/tasks/main.yml @@ -136,6 +136,18 @@ - (result.instances|length) == 1 - "result.instances[0].state.name == 'running'" + - name: test second instance is stopped + ec2: + instance_ids: "{{ test_instance_2.instance_ids }}" + state: stopped + wait: yes + register: result + + - name: assert second instance is stopped + assert: + that: + - "result.instances[0].state == 'stopped'" + # ======================================================== always: