From 80f39993285b0a54fd377c7556f6570dbddb2cf6 Mon Sep 17 00:00:00 2001 From: Trevor Anderson Date: Thu, 14 Jan 2021 12:37:33 -0600 Subject: [PATCH 1/3] remove instance-state-name inverse filters in favor of standard value filters on other 4 accepted options to fix bad aws return --- plugins/modules/ec2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'] From 52481c6a2a45d03e9fda3e87d45ac842a5fe3bee Mon Sep 17 00:00:00 2001 From: Trevor Anderson Date: Mon, 18 Jan 2021 08:25:46 -0600 Subject: [PATCH 2/3] adding changelog fragment 237_replace_inverse_ec2_aws_filter --- changelogs/fragments/237_replace_inverse_ec2_aws_filter.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/237_replace_inverse_ec2_aws_filter.yaml 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) From b33390c906bbc6a99bf0df6cda60cb15f21727c9 Mon Sep 17 00:00:00 2001 From: Trevor Anderson Date: Mon, 18 Jan 2021 11:40:06 -0600 Subject: [PATCH 3/3] Adding ec2 test to stop second instance and assert it is stopped. --- tests/integration/targets/ec2/tasks/main.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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: