From 08746a1ea6105cc0047ff1faa43b7065fc062c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Mon, 29 Aug 2022 15:16:52 -0400 Subject: [PATCH] tests: split up ec2_instance (#979) tests: split up ec2_instance Use on target per sub-test to have a better control on the global execution time and simplify the troubleshooting. Reviewed-by: Mark Chappell --- .../979-ec2_instance_tests_split.yaml | 3 + .../targets/ec2_instance/inventory | 20 --- .../integration/targets/ec2_instance/main.yml | 40 ------ .../roles/ec2_instance/meta/main.yml | 7 -- .../roles/ec2_instance/tasks/env_cleanup.yml | 79 ------------ .../roles/ec2_instance/tasks/find_ami.yml | 15 --- .../roles/ec2_instance/tasks/main.yml | 56 --------- .../integration/targets/ec2_instance/runme.sh | 12 -- .../ec2_instance_block_devices/aliases | 5 + .../defaults/main.yml | 4 + .../ec2_instance_block_devices/meta/main.yml | 6 + .../tasks/main.yml} | 18 ++- .../ec2_instance_checkmode_tests/aliases | 5 + .../defaults/main.yml | 4 + .../meta/main.yml | 6 + .../tasks/main.yml} | 8 +- .../targets/ec2_instance_cpu_options/aliases | 5 + .../defaults/main.yml | 4 + .../ec2_instance_cpu_options/meta/main.yml | 6 + .../tasks/main.yml} | 17 ++- .../ec2_instance_default_vpc_tests/aliases | 5 + .../defaults/main.yml | 4 + .../meta/main.yml | 6 + .../tasks/main.yml} | 8 +- .../ec2_instance_ebs_optimized/aliases | 5 + .../defaults/main.yml | 4 + .../ec2_instance_ebs_optimized/meta/main.yml | 6 + .../tasks/main.yml} | 24 ++-- .../aliases | 5 + .../defaults/main.yml | 4 + .../meta/main.yml | 6 + .../tasks/main.yml} | 31 ++--- .../ec2_instance_iam_instance_role/aliases | 5 + .../defaults/main.yml | 7 ++ .../files/assume-role-policy.json | 0 .../meta/main.yml | 6 + .../tasks/main.yml} | 16 ++- .../ec2_instance_instance_minimal/aliases | 5 + .../defaults/main.yml | 4 + .../meta/main.yml | 6 + .../tasks/main.yml} | 20 ++- .../aliases | 3 +- .../defaults/main.yml | 4 + .../meta/main.yml | 6 + .../tasks/main.yml} | 9 +- .../ec2_instance_instance_no_wait/aliases | 5 + .../defaults/main.yml | 4 + .../meta/main.yml | 6 + .../tasks/main.yml} | 24 ++-- .../ec2_instance_metadata_options/aliases | 5 + .../defaults/main.yml | 4 + .../meta/main.yml | 9 ++ .../tasks/main.yml} | 21 ++-- .../ec2_instance_security_group/aliases | 5 + .../defaults/main.yml | 4 + .../ec2_instance_security_group/meta/main.yml | 6 + .../tasks/main.yml} | 8 +- .../ec2_instance_state_config_updates/aliases | 5 + .../defaults/main.yml | 4 + .../meta/main.yml | 6 + .../tasks/main.yml} | 27 ++-- .../aliases | 5 + .../defaults/main.yml | 4 + .../meta/main.yml | 6 + .../tasks/main.yml} | 27 ++-- .../aliases | 5 + .../defaults/main.yml | 4 + .../meta/main.yml | 6 + .../tasks/main.yml} | 25 ++-- .../targets/ec2_instance_uptime/aliases | 5 + .../ec2_instance_uptime/defaults/main.yml | 4 + .../meta/main.yml | 4 +- .../tasks/main.yml} | 17 ++- .../defaults/main.yml | 12 +- .../setup_ec2_instance_env/handlers/main.yml | 2 + .../setup_ec2_instance_env/meta/main.yml | 1 + .../setup_ec2_instance_env/tasks/cleanup.yml | 118 ++++++++++++++++++ .../tasks/main.yml} | 8 ++ 78 files changed, 496 insertions(+), 419 deletions(-) create mode 100644 changelogs/fragments/979-ec2_instance_tests_split.yaml delete mode 100644 tests/integration/targets/ec2_instance/inventory delete mode 100644 tests/integration/targets/ec2_instance/main.yml delete mode 100644 tests/integration/targets/ec2_instance/roles/ec2_instance/meta/main.yml delete mode 100644 tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/env_cleanup.yml delete mode 100644 tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/find_ami.yml delete mode 100644 tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/main.yml delete mode 100755 tests/integration/targets/ec2_instance/runme.sh create mode 100644 tests/integration/targets/ec2_instance_block_devices/aliases create mode 100644 tests/integration/targets/ec2_instance_block_devices/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_block_devices/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/block_devices.yml => ec2_instance_block_devices/tasks/main.yml} (93%) create mode 100644 tests/integration/targets/ec2_instance_checkmode_tests/aliases create mode 100644 tests/integration/targets/ec2_instance_checkmode_tests/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_checkmode_tests/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/checkmode_tests.yml => ec2_instance_checkmode_tests/tasks/main.yml} (96%) create mode 100644 tests/integration/targets/ec2_instance_cpu_options/aliases create mode 100644 tests/integration/targets/ec2_instance_cpu_options/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_cpu_options/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/cpu_options.yml => ec2_instance_cpu_options/tasks/main.yml} (92%) create mode 100644 tests/integration/targets/ec2_instance_default_vpc_tests/aliases create mode 100644 tests/integration/targets/ec2_instance_default_vpc_tests/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_default_vpc_tests/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/default_vpc_tests.yml => ec2_instance_default_vpc_tests/tasks/main.yml} (88%) create mode 100644 tests/integration/targets/ec2_instance_ebs_optimized/aliases create mode 100644 tests/integration/targets/ec2_instance_ebs_optimized/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_ebs_optimized/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/ebs_optimized.yml => ec2_instance_ebs_optimized/tasks/main.yml} (66%) create mode 100644 tests/integration/targets/ec2_instance_external_resource_attach/aliases create mode 100644 tests/integration/targets/ec2_instance_external_resource_attach/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_external_resource_attach/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/external_resource_attach.yml => ec2_instance_external_resource_attach/tasks/main.yml} (86%) create mode 100644 tests/integration/targets/ec2_instance_iam_instance_role/aliases create mode 100644 tests/integration/targets/ec2_instance_iam_instance_role/defaults/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance => ec2_instance_iam_instance_role}/files/assume-role-policy.json (100%) create mode 100644 tests/integration/targets/ec2_instance_iam_instance_role/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/iam_instance_role.yml => ec2_instance_iam_instance_role/tasks/main.yml} (91%) create mode 100644 tests/integration/targets/ec2_instance_instance_minimal/aliases create mode 100644 tests/integration/targets/ec2_instance_instance_minimal/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_instance_minimal/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/instance_minimal.yml => ec2_instance_instance_minimal/tasks/main.yml} (98%) rename tests/integration/targets/{ec2_instance => ec2_instance_instance_multiple}/aliases (69%) create mode 100644 tests/integration/targets/ec2_instance_instance_multiple/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_instance_multiple/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/instance_multiple.yml => ec2_instance_instance_multiple/tasks/main.yml} (98%) create mode 100644 tests/integration/targets/ec2_instance_instance_no_wait/aliases create mode 100644 tests/integration/targets/ec2_instance_instance_no_wait/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_instance_no_wait/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/instance_no_wait.yml => ec2_instance_instance_no_wait/tasks/main.yml} (80%) create mode 100644 tests/integration/targets/ec2_instance_metadata_options/aliases create mode 100644 tests/integration/targets/ec2_instance_metadata_options/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_metadata_options/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/metadata_options.yml => ec2_instance_metadata_options/tasks/main.yml} (88%) create mode 100644 tests/integration/targets/ec2_instance_security_group/aliases create mode 100644 tests/integration/targets/ec2_instance_security_group/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_security_group/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/security_group.yml => ec2_instance_security_group/tasks/main.yml} (92%) create mode 100644 tests/integration/targets/ec2_instance_state_config_updates/aliases create mode 100644 tests/integration/targets/ec2_instance_state_config_updates/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_state_config_updates/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/state_config_updates.yml => ec2_instance_state_config_updates/tasks/main.yml} (91%) create mode 100644 tests/integration/targets/ec2_instance_tags_and_vpc_settings/aliases create mode 100644 tests/integration/targets/ec2_instance_tags_and_vpc_settings/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_tags_and_vpc_settings/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/tags_and_vpc_settings.yml => ec2_instance_tags_and_vpc_settings/tasks/main.yml} (92%) create mode 100644 tests/integration/targets/ec2_instance_termination_protection/aliases create mode 100644 tests/integration/targets/ec2_instance_termination_protection/defaults/main.yml create mode 100644 tests/integration/targets/ec2_instance_termination_protection/meta/main.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/termination_protection.yml => ec2_instance_termination_protection/tasks/main.yml} (95%) create mode 100644 tests/integration/targets/ec2_instance_uptime/aliases create mode 100644 tests/integration/targets/ec2_instance_uptime/defaults/main.yml rename tests/integration/targets/{ec2_instance => ec2_instance_uptime}/meta/main.yml (59%) rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/uptime.yml => ec2_instance_uptime/tasks/main.yml} (87%) rename tests/integration/targets/{ec2_instance/roles/ec2_instance => setup_ec2_instance_env}/defaults/main.yml (62%) create mode 100644 tests/integration/targets/setup_ec2_instance_env/handlers/main.yml create mode 100644 tests/integration/targets/setup_ec2_instance_env/meta/main.yml create mode 100644 tests/integration/targets/setup_ec2_instance_env/tasks/cleanup.yml rename tests/integration/targets/{ec2_instance/roles/ec2_instance/tasks/env_setup.yml => setup_ec2_instance_env/tasks/main.yml} (86%) diff --git a/changelogs/fragments/979-ec2_instance_tests_split.yaml b/changelogs/fragments/979-ec2_instance_tests_split.yaml new file mode 100644 index 00000000000..4838cc1b60d --- /dev/null +++ b/changelogs/fragments/979-ec2_instance_tests_split.yaml @@ -0,0 +1,3 @@ +--- +trivial: +- "ec2_instance tests - ec2_instance integration test is now splitted up in several independent tests (https://github.com/ansible-collections/amazon.aws/pull/979)." diff --git a/tests/integration/targets/ec2_instance/inventory b/tests/integration/targets/ec2_instance/inventory deleted file mode 100644 index e063f5745c0..00000000000 --- a/tests/integration/targets/ec2_instance/inventory +++ /dev/null @@ -1,20 +0,0 @@ -[tests] -instance_minimal -instance_multiple -checkmode_tests -termination_protection -ebs_optimized -block_devices -cpu_options -metadata_options -default_vpc_tests -external_resource_attach -instance_no_wait -iam_instance_role -tags_and_vpc_settings -security_group -state_config_updates - -[all:vars] -ansible_connection=local -ansible_python_interpreter="{{ ansible_playbook_python }}" diff --git a/tests/integration/targets/ec2_instance/main.yml b/tests/integration/targets/ec2_instance/main.yml deleted file mode 100644 index 2261245a158..00000000000 --- a/tests/integration/targets/ec2_instance/main.yml +++ /dev/null @@ -1,40 +0,0 @@ ---- -# Beware: most of our tests here are run in parallel. -# To add new tests you'll need to add a new host to the inventory and a matching -# '{{ inventory_hostname }}'.yml file in roles/ec2_instance/tasks/ - - -# Prepare the VPC and figure out which AMI to use -- hosts: all - gather_facts: no - tasks: - - module_defaults: - group/aws: - aws_access_key: "{{ aws_access_key }}" - aws_secret_key: "{{ aws_secret_key }}" - security_token: "{{ security_token | default(omit) }}" - region: "{{ aws_region }}" - vars: - # We can't just use "run_once" because the facts don't propagate when - # running an 'include' that was run_once - setup_run_once: yes - block: - - include_role: - name: 'ec2_instance' - tasks_from: env_setup.yml - rescue: - - include_role: - name: 'ec2_instance' - tasks_from: env_cleanup.yml - run_once: yes - - fail: - msg: 'Environment preparation failed' - run_once: yes - -# VPC should get cleaned up once all hosts have run -- hosts: all - gather_facts: no - strategy: free - serial: 7 - roles: - - ec2_instance diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/meta/main.yml b/tests/integration/targets/ec2_instance/roles/ec2_instance/meta/main.yml deleted file mode 100644 index ee6b1d5a3b0..00000000000 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/meta/main.yml +++ /dev/null @@ -1,7 +0,0 @@ -dependencies: -- role: setup_ec2_facts -- role: setup_botocore_pip - vars: - boto3_version: "1.20.30" -collections: -- amazon.aws diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/env_cleanup.yml b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/env_cleanup.yml deleted file mode 100644 index bdd69fecc44..00000000000 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/env_cleanup.yml +++ /dev/null @@ -1,79 +0,0 @@ -- name: "remove Instances" - ec2_instance: - state: absent - filters: - vpc-id: "{{ testing_vpc.vpc.id }}" - wait: yes - ignore_errors: yes - retries: 10 - -- name: "remove ENIs" - ec2_eni_info: - filters: - vpc-id: "{{ testing_vpc.vpc.id }}" - register: enis - -- name: "delete all ENIs" - ec2_eni: - state: absent - eni_id: "{{ item.id }}" - register: removed - until: removed is not failed - with_items: "{{ enis.network_interfaces }}" - ignore_errors: yes - retries: 10 - -- name: "remove the security group" - ec2_group: - state: absent - name: "{{ resource_prefix }}-sg" - description: a security group for ansible tests - vpc_id: "{{ testing_vpc.vpc.id }}" - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - -- name: "remove the second security group" - ec2_group: - name: "{{ resource_prefix }}-sg-2" - description: a security group for ansible tests - vpc_id: "{{ testing_vpc.vpc.id }}" - state: absent - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - -- name: "remove subnet A" - ec2_vpc_subnet: - state: absent - vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: "{{ subnet_a_cidr }}" - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - -- name: "remove subnet B" - ec2_vpc_subnet: - state: absent - vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: "{{ subnet_b_cidr }}" - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - -- name: "remove the VPC" - ec2_vpc_net: - state: absent - name: "{{ vpc_name }}" - cidr_block: "{{ vpc_cidr }}" - tags: - Name: Ansible Testing VPC - tenancy: default - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/find_ami.yml b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/find_ami.yml deleted file mode 100644 index 5c0e61f84c6..00000000000 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/find_ami.yml +++ /dev/null @@ -1,15 +0,0 @@ -- run_once: '{{ setup_run_once | default("no") | bool }}' - block: - - name: "Find AMI to use" - run_once: yes - ec2_ami_info: - owners: 'amazon' - filters: - name: '{{ ec2_ami_name }}' - register: ec2_amis - - name: "Set fact with latest AMI" - run_once: yes - vars: - latest_ami: '{{ ec2_amis.images | sort(attribute="creation_date") | last }}' - set_fact: - ec2_ami_image: '{{ latest_ami.image_id }}' diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/main.yml b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/main.yml deleted file mode 100644 index 65645d2fa08..00000000000 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/main.yml +++ /dev/null @@ -1,56 +0,0 @@ ---- -# Beware: most of our tests here are run in parallel. -# To add new tests you'll need to add a new host to the inventory and a matching -# '{{ inventory_hostname }}'.yml file in roles/ec2_instance/tasks/ -# -# Please make sure you tag your instances with -# tags: -# "tag:TestId": "{{ ec2_instance_tag_TestId }}" -# And delete them based off that tag at the end of your specific set of tests -# -# ############################################################################### -# -# A Note about ec2 environment variable name preference: -# - EC2_URL -> AWS_URL -# - EC2_ACCESS_KEY -> AWS_ACCESS_KEY_ID -> AWS_ACCESS_KEY -# - EC2_SECRET_KEY -> AWS_SECRET_ACCESS_KEY -> AWX_SECRET_KEY -# - EC2_REGION -> AWS_REGION -# - -- name: "Wrap up all tests and setup AWS credentials" - module_defaults: - group/aws: - aws_access_key: "{{ aws_access_key }}" - aws_secret_key: "{{ aws_secret_key }}" - security_token: "{{ security_token | default(omit) }}" - region: "{{ aws_region }}" - aws_config: - retries: - # Unfortunately AWSRetry doesn't support paginators and boto3's paginators - # don't support any configuration of the delay between retries. - max_attempts: 20 - collections: - - amazon.aws - - community.aws - block: - - debug: - msg: "{{ inventory_hostname }} start: {{ lookup('pipe','date') }}" - - include_tasks: '{{ inventory_hostname }}.yml' - - debug: - msg: "{{ inventory_hostname }} finish: {{ lookup('pipe','date') }}" - - always: - - set_fact: - _role_complete: True - - vars: - completed_hosts: '{{ ansible_play_hosts_all | map("extract", hostvars, "_role_complete") | list | select("defined") | list | length }}' - hosts_in_play: '{{ ansible_play_hosts_all | length }}' - debug: - msg: "{{ completed_hosts }} of {{ hosts_in_play }} complete" - - include_tasks: env_cleanup.yml - vars: - completed_hosts: '{{ ansible_play_hosts_all | map("extract", hostvars, "_role_complete") | list | select("defined") | list | length }}' - hosts_in_play: '{{ ansible_play_hosts_all | length }}' - when: - - aws_cleanup - - completed_hosts == hosts_in_play diff --git a/tests/integration/targets/ec2_instance/runme.sh b/tests/integration/targets/ec2_instance/runme.sh deleted file mode 100755 index aa324772bbe..00000000000 --- a/tests/integration/targets/ec2_instance/runme.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -# -# Beware: most of our tests here are run in parallel. -# To add new tests you'll need to add a new host to the inventory and a matching -# '{{ inventory_hostname }}'.yml file in roles/ec2_instance/tasks/ - - -set -eux - -export ANSIBLE_ROLES_PATH=../ - -ansible-playbook main.yml -i inventory "$@" diff --git a/tests/integration/targets/ec2_instance_block_devices/aliases b/tests/integration/targets/ec2_instance_block_devices/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_block_devices/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_block_devices/defaults/main.yml b/tests/integration/targets/ec2_instance_block_devices/defaults/main.yml new file mode 100644 index 00000000000..0b6859c6ad7 --- /dev/null +++ b/tests/integration/targets/ec2_instance_block_devices/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-block-devices' diff --git a/tests/integration/targets/ec2_instance_block_devices/meta/main.yml b/tests/integration/targets/ec2_instance_block_devices/meta/main.yml new file mode 100644 index 00000000000..3207286058e --- /dev/null +++ b/tests/integration/targets/ec2_instance_block_devices/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: block_devices diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml b/tests/integration/targets/ec2_instance_block_devices/tasks/main.yml similarity index 93% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml rename to tests/integration/targets/ec2_instance_block_devices/tasks/main.yml index ff01afb2f12..5e27d5ab0b2 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml +++ b/tests/integration/targets/ec2_instance_block_devices/tasks/main.yml @@ -1,5 +1,10 @@ -- block: - +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: - name: "New instance with an extra block device" ec2_instance: state: running @@ -103,12 +108,3 @@ - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.VolumeType == 'gp3' - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.VolumeSize == 20 - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.Throughput == 500 - - always: - - name: "Terminate block_devices instances" - ec2_instance: - state: absent - filters: - "tag:TestId": "{{ ec2_instance_tag_TestId }}" - wait: yes - ignore_errors: yes diff --git a/tests/integration/targets/ec2_instance_checkmode_tests/aliases b/tests/integration/targets/ec2_instance_checkmode_tests/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_checkmode_tests/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_checkmode_tests/defaults/main.yml b/tests/integration/targets/ec2_instance_checkmode_tests/defaults/main.yml new file mode 100644 index 00000000000..da06ab2bfa9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_checkmode_tests/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-checkmode' diff --git a/tests/integration/targets/ec2_instance_checkmode_tests/meta/main.yml b/tests/integration/targets/ec2_instance_checkmode_tests/meta/main.yml new file mode 100644 index 00000000000..634b3aa6e62 --- /dev/null +++ b/tests/integration/targets/ec2_instance_checkmode_tests/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: check_mode diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/checkmode_tests.yml b/tests/integration/targets/ec2_instance_checkmode_tests/tasks/main.yml similarity index 96% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/checkmode_tests.yml rename to tests/integration/targets/ec2_instance_checkmode_tests/tasks/main.yml index f9092882a0a..2ffa2f9df5c 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/checkmode_tests.yml +++ b/tests/integration/targets/ec2_instance_checkmode_tests/tasks/main.yml @@ -1,4 +1,10 @@ -- block: +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: - name: "Make basic instance" ec2_instance: state: present diff --git a/tests/integration/targets/ec2_instance_cpu_options/aliases b/tests/integration/targets/ec2_instance_cpu_options/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_cpu_options/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_cpu_options/defaults/main.yml b/tests/integration/targets/ec2_instance_cpu_options/defaults/main.yml new file mode 100644 index 00000000000..96a3d24a584 --- /dev/null +++ b/tests/integration/targets/ec2_instance_cpu_options/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-cpu-options' diff --git a/tests/integration/targets/ec2_instance_cpu_options/meta/main.yml b/tests/integration/targets/ec2_instance_cpu_options/meta/main.yml new file mode 100644 index 00000000000..2d7d140d450 --- /dev/null +++ b/tests/integration/targets/ec2_instance_cpu_options/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: cpu_options diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/cpu_options.yml b/tests/integration/targets/ec2_instance_cpu_options/tasks/main.yml similarity index 92% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/cpu_options.yml rename to tests/integration/targets/ec2_instance_cpu_options/tasks/main.yml index 7eb2b6aeb38..a0bdd410696 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/cpu_options.yml +++ b/tests/integration/targets/ec2_instance_cpu_options/tasks/main.yml @@ -1,4 +1,10 @@ -- block: +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: - name: "create t3.nano instance with cpu_options" ec2_instance: state: present @@ -77,12 +83,3 @@ assert: that: - "{{ checkmode_instance_fact.instances | length }} == 0" - - always: - - name: "Terminate cpu_options instances" - ec2_instance: - state: absent - filters: - "tag:TestId": "{{ ec2_instance_tag_TestId }}" - wait: yes - ignore_errors: yes diff --git a/tests/integration/targets/ec2_instance_default_vpc_tests/aliases b/tests/integration/targets/ec2_instance_default_vpc_tests/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_default_vpc_tests/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_default_vpc_tests/defaults/main.yml b/tests/integration/targets/ec2_instance_default_vpc_tests/defaults/main.yml new file mode 100644 index 00000000000..04d57864e5b --- /dev/null +++ b/tests/integration/targets/ec2_instance_default_vpc_tests/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-default-vpc' diff --git a/tests/integration/targets/ec2_instance_default_vpc_tests/meta/main.yml b/tests/integration/targets/ec2_instance_default_vpc_tests/meta/main.yml new file mode 100644 index 00000000000..7622736b49f --- /dev/null +++ b/tests/integration/targets/ec2_instance_default_vpc_tests/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: default_vpc diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/default_vpc_tests.yml b/tests/integration/targets/ec2_instance_default_vpc_tests/tasks/main.yml similarity index 88% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/default_vpc_tests.yml rename to tests/integration/targets/ec2_instance_default_vpc_tests/tasks/main.yml index 1887559d1e7..3abcf0f8a28 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/default_vpc_tests.yml +++ b/tests/integration/targets/ec2_instance_default_vpc_tests/tasks/main.yml @@ -1,4 +1,10 @@ -- block: +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: - name: "Make instance in a default subnet of the VPC" ec2_instance: state: present diff --git a/tests/integration/targets/ec2_instance_ebs_optimized/aliases b/tests/integration/targets/ec2_instance_ebs_optimized/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_ebs_optimized/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_ebs_optimized/defaults/main.yml b/tests/integration/targets/ec2_instance_ebs_optimized/defaults/main.yml new file mode 100644 index 00000000000..0ceb6671d8f --- /dev/null +++ b/tests/integration/targets/ec2_instance_ebs_optimized/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-ebs-optimized' diff --git a/tests/integration/targets/ec2_instance_ebs_optimized/meta/main.yml b/tests/integration/targets/ec2_instance_ebs_optimized/meta/main.yml new file mode 100644 index 00000000000..9ee97b6f41b --- /dev/null +++ b/tests/integration/targets/ec2_instance_ebs_optimized/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: ebs_optimized diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/ebs_optimized.yml b/tests/integration/targets/ec2_instance_ebs_optimized/tasks/main.yml similarity index 66% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/ebs_optimized.yml rename to tests/integration/targets/ec2_instance_ebs_optimized/tasks/main.yml index 728c6c016e4..d01ee77ee5c 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/ebs_optimized.yml +++ b/tests/integration/targets/ec2_instance_ebs_optimized/tasks/main.yml @@ -1,4 +1,10 @@ -- block: +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: - name: "Make EBS optimized instance in the testing subnet of the test VPC" ec2_instance: state: present @@ -23,19 +29,3 @@ assert: that: - "{{ ebs_opt_instance_info.instances.0.ebs_optimized }}" - - - name: "Terminate instances" - ec2_instance: - state: absent - instance_ids: "{{ ebs_opt_in_vpc.instance_ids }}" - tags: - TestId: "{{ ec2_instance_tag_TestId }}" - - always: - - name: "Terminate ebs_optimzed instances" - ec2_instance: - state: absent - filters: - "tag:TestId": "{{ ec2_instance_tag_TestId }}" - wait: yes - ignore_errors: yes diff --git a/tests/integration/targets/ec2_instance_external_resource_attach/aliases b/tests/integration/targets/ec2_instance_external_resource_attach/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_external_resource_attach/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_external_resource_attach/defaults/main.yml b/tests/integration/targets/ec2_instance_external_resource_attach/defaults/main.yml new file mode 100644 index 00000000000..1d7ab83c867 --- /dev/null +++ b/tests/integration/targets/ec2_instance_external_resource_attach/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-external-attach' diff --git a/tests/integration/targets/ec2_instance_external_resource_attach/meta/main.yml b/tests/integration/targets/ec2_instance_external_resource_attach/meta/main.yml new file mode 100644 index 00000000000..f30ad80c4e0 --- /dev/null +++ b/tests/integration/targets/ec2_instance_external_resource_attach/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: external_resources diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/external_resource_attach.yml b/tests/integration/targets/ec2_instance_external_resource_attach/tasks/main.yml similarity index 86% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/external_resource_attach.yml rename to tests/integration/targets/ec2_instance_external_resource_attach/tasks/main.yml index 06c353b9156..74943a3fdbf 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/external_resource_attach.yml +++ b/tests/integration/targets/ec2_instance_external_resource_attach/tasks/main.yml @@ -1,4 +1,10 @@ -- block: +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: # Make custom ENIs and attach via the `network` parameter - ec2_eni: state: present @@ -104,26 +110,3 @@ that: - "{{ presented_instance_fact.instances | length }} > 0" - "{{ checkmode_instance_fact.instances | length }} == 0" - - always: - - name: "Terminate external_resource_attach instances" - ec2_instance: - state: absent - filters: - "tag:TestId": "{{ ec2_instance_tag_TestId }}" - wait: yes - ignore_errors: yes - - - ec2_key: - state: absent - name: "{{ resource_prefix }}_test_key" - ignore_errors: yes - - - ec2_eni: - state: absent - eni_id: '{{ item.interface.id }}' - ignore_errors: yes - with_items: - - '{{ eni_a }}' - - '{{ eni_b }}' - - '{{ eni_c }}' diff --git a/tests/integration/targets/ec2_instance_iam_instance_role/aliases b/tests/integration/targets/ec2_instance_iam_instance_role/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_iam_instance_role/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_iam_instance_role/defaults/main.yml b/tests/integration/targets/ec2_instance_iam_instance_role/defaults/main.yml new file mode 100644 index 00000000000..51b1df85392 --- /dev/null +++ b/tests/integration/targets/ec2_instance_iam_instance_role/defaults/main.yml @@ -0,0 +1,7 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-profile' + +first_iam_role: "ansible-test-{{ tiny_prefix }}-instance_role" +second_iam_role: "ansible-test-{{ tiny_prefix }}-instance_role-2" diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/files/assume-role-policy.json b/tests/integration/targets/ec2_instance_iam_instance_role/files/assume-role-policy.json similarity index 100% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/files/assume-role-policy.json rename to tests/integration/targets/ec2_instance_iam_instance_role/files/assume-role-policy.json diff --git a/tests/integration/targets/ec2_instance_iam_instance_role/meta/main.yml b/tests/integration/targets/ec2_instance_iam_instance_role/meta/main.yml new file mode 100644 index 00000000000..1e3a6043a9a --- /dev/null +++ b/tests/integration/targets/ec2_instance_iam_instance_role/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: instance_role diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/iam_instance_role.yml b/tests/integration/targets/ec2_instance_iam_instance_role/tasks/main.yml similarity index 91% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/iam_instance_role.yml rename to tests/integration/targets/ec2_instance_iam_instance_role/tasks/main.yml index 0a45d297120..2f28ae3b8ec 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/iam_instance_role.yml +++ b/tests/integration/targets/ec2_instance_iam_instance_role/tasks/main.yml @@ -1,4 +1,10 @@ -- block: +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: - name: "Create IAM role for test" iam_role: state: present @@ -31,7 +37,7 @@ image_id: "{{ ec2_ami_id }}" security_groups: "{{ sg.group_id }}" instance_type: "{{ ec2_instance_type }}" - instance_role: "ansible-test-sts-{{ unique_id }}-test-policy" + instance_role: "{{ first_iam_role }}" vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}" tags: TestId: "{{ ec2_instance_tag_TestId }}" @@ -102,6 +108,7 @@ - 'updates_instance_info.instances[0].instance_id == instance_with_role.instances[0].instance_id' always: + # We need to delete the instances before we can delete the roles - name: "Terminate iam_instance_role instances" ec2_instance: state: absent @@ -114,10 +121,7 @@ iam_role: state: absent name: "{{ item }}" - assume_role_policy_document: "{{ lookup('file','assume-role-policy.json') }}" - create_instance_profile: yes - managed_policy: - - AmazonEC2ContainerServiceRole + delete_instance_profile: true loop: - '{{ first_iam_role }}' - '{{ second_iam_role }}' diff --git a/tests/integration/targets/ec2_instance_instance_minimal/aliases b/tests/integration/targets/ec2_instance_instance_minimal/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_instance_minimal/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_instance_minimal/defaults/main.yml b/tests/integration/targets/ec2_instance_instance_minimal/defaults/main.yml new file mode 100644 index 00000000000..b43f94a50b8 --- /dev/null +++ b/tests/integration/targets/ec2_instance_instance_minimal/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-minimal' diff --git a/tests/integration/targets/ec2_instance_instance_minimal/meta/main.yml b/tests/integration/targets/ec2_instance_instance_minimal/meta/main.yml new file mode 100644 index 00000000000..7fa5de5558c --- /dev/null +++ b/tests/integration/targets/ec2_instance_instance_minimal/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: minimal diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/instance_minimal.yml b/tests/integration/targets/ec2_instance_instance_minimal/tasks/main.yml similarity index 98% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/instance_minimal.yml rename to tests/integration/targets/ec2_instance_instance_minimal/tasks/main.yml index 574cc14bc0c..f96829b9da0 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/instance_minimal.yml +++ b/tests/integration/targets/ec2_instance_instance_minimal/tasks/main.yml @@ -1,5 +1,10 @@ -- block: - +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: - name: "Create a new instance (check_mode)" ec2_instance: state: present @@ -476,14 +481,3 @@ - '"ec2:TerminateInstances" not in terminate_id.resource_actions' - '"terminate_failed" not in terminate_id' - '"terminate_success" not in terminate_id' - -################################################################ - - always: - - name: "Terminate instance_no_wait instances" - ec2_instance: - state: absent - filters: - "tag:TestId": "{{ ec2_instance_tag_TestId }}" - wait: yes - ignore_errors: yes diff --git a/tests/integration/targets/ec2_instance/aliases b/tests/integration/targets/ec2_instance_instance_multiple/aliases similarity index 69% rename from tests/integration/targets/ec2_instance/aliases rename to tests/integration/targets/ec2_instance_instance_multiple/aliases index 0a6ae9e0354..426bafaa06a 100644 --- a/tests/integration/targets/ec2_instance/aliases +++ b/tests/integration/targets/ec2_instance_instance_multiple/aliases @@ -1,5 +1,6 @@ -# duration: 25 slow cloud/aws + ec2_instance_info +ec2_instance diff --git a/tests/integration/targets/ec2_instance_instance_multiple/defaults/main.yml b/tests/integration/targets/ec2_instance_instance_multiple/defaults/main.yml new file mode 100644 index 00000000000..5c81b54880c --- /dev/null +++ b/tests/integration/targets/ec2_instance_instance_multiple/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-multiple' diff --git a/tests/integration/targets/ec2_instance_instance_multiple/meta/main.yml b/tests/integration/targets/ec2_instance_instance_multiple/meta/main.yml new file mode 100644 index 00000000000..c3ba887f74d --- /dev/null +++ b/tests/integration/targets/ec2_instance_instance_multiple/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: multiple_instances diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/instance_multiple.yml b/tests/integration/targets/ec2_instance_instance_multiple/tasks/main.yml similarity index 98% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/instance_multiple.yml rename to tests/integration/targets/ec2_instance_instance_multiple/tasks/main.yml index 9c32b9d042a..491b58391a3 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/instance_multiple.yml +++ b/tests/integration/targets/ec2_instance_instance_multiple/tasks/main.yml @@ -1,5 +1,10 @@ -- block: - +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: ################################################################ - name: "Create multiple instance (check_mode)" diff --git a/tests/integration/targets/ec2_instance_instance_no_wait/aliases b/tests/integration/targets/ec2_instance_instance_no_wait/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_instance_no_wait/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_instance_no_wait/defaults/main.yml b/tests/integration/targets/ec2_instance_instance_no_wait/defaults/main.yml new file mode 100644 index 00000000000..0f422a6f5bd --- /dev/null +++ b/tests/integration/targets/ec2_instance_instance_no_wait/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-no-wait' diff --git a/tests/integration/targets/ec2_instance_instance_no_wait/meta/main.yml b/tests/integration/targets/ec2_instance_instance_no_wait/meta/main.yml new file mode 100644 index 00000000000..3014864e5fb --- /dev/null +++ b/tests/integration/targets/ec2_instance_instance_no_wait/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: no_wait diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/instance_no_wait.yml b/tests/integration/targets/ec2_instance_instance_no_wait/tasks/main.yml similarity index 80% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/instance_no_wait.yml rename to tests/integration/targets/ec2_instance_instance_no_wait/tasks/main.yml index 78e3c360550..f279e46c381 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/instance_no_wait.yml +++ b/tests/integration/targets/ec2_instance_instance_no_wait/tasks/main.yml @@ -1,4 +1,10 @@ -- block: +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: - name: "New instance and don't wait for it to complete" ec2_instance: state: present @@ -50,19 +56,3 @@ that: - "{{ real_instance_fact.instances | length }} > 0" - "{{ checkmode_instance_fact.instances | length }} == 0" - - - name: "Terminate instances" - ec2_instance: - state: absent - instance_ids: "{{ in_test_vpc.instance_ids }}" - tags: - TestId: "{{ ec2_instance_tag_TestId }}" - - always: - - name: "Terminate instance_no_wait instances" - ec2_instance: - state: absent - filters: - "tag:TestId": "{{ ec2_instance_tag_TestId }}" - wait: yes - ignore_errors: yes diff --git a/tests/integration/targets/ec2_instance_metadata_options/aliases b/tests/integration/targets/ec2_instance_metadata_options/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_metadata_options/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_metadata_options/defaults/main.yml b/tests/integration/targets/ec2_instance_metadata_options/defaults/main.yml new file mode 100644 index 00000000000..cc18f67ce36 --- /dev/null +++ b/tests/integration/targets/ec2_instance_metadata_options/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-metadata' diff --git a/tests/integration/targets/ec2_instance_metadata_options/meta/main.yml b/tests/integration/targets/ec2_instance_metadata_options/meta/main.yml new file mode 100644 index 00000000000..78ebf425e82 --- /dev/null +++ b/tests/integration/targets/ec2_instance_metadata_options/meta/main.yml @@ -0,0 +1,9 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_botocore_pip + vars: + botocore_version: 1.23.30 +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: metadata diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/metadata_options.yml b/tests/integration/targets/ec2_instance_metadata_options/tasks/main.yml similarity index 88% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/metadata_options.yml rename to tests/integration/targets/ec2_instance_metadata_options/tasks/main.yml index 3fbcf1f209d..57d58815188 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/metadata_options.yml +++ b/tests/integration/targets/ec2_instance_metadata_options/tasks/main.yml @@ -1,4 +1,10 @@ - name: test with boto3 version that does not support instance_metadata_tags + module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" block: - name: "fail create t3.nano instance with metadata_options" ec2_instance: @@ -27,6 +33,12 @@ - name: test with boto3 version that supports instance_metadata_tags vars: ansible_python_interpreter: "{{ botocore_virtualenv_interpreter }}" + module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" block: - name: "create t3.nano instance with metadata_options" ec2_instance: @@ -84,12 +96,3 @@ - "'{{ presented_instance_fact.instances.0.state.name }}' in ['running','pending']" - "'{{ presented_instance_fact.instances.0.metadata_options.http_endpoint }}' == 'enabled'" - "'{{ presented_instance_fact.instances.0.metadata_options.http_tokens }}' == 'required'" - - always: - - name: "Terminate metadata_options instances" - ec2_instance: - state: absent - filters: - "tag:TestId": "{{ ec2_instance_tag_TestId }}" - wait: yes - ignore_errors: yes diff --git a/tests/integration/targets/ec2_instance_security_group/aliases b/tests/integration/targets/ec2_instance_security_group/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_security_group/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_security_group/defaults/main.yml b/tests/integration/targets/ec2_instance_security_group/defaults/main.yml new file mode 100644 index 00000000000..f7a141a62f2 --- /dev/null +++ b/tests/integration/targets/ec2_instance_security_group/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-sg' diff --git a/tests/integration/targets/ec2_instance_security_group/meta/main.yml b/tests/integration/targets/ec2_instance_security_group/meta/main.yml new file mode 100644 index 00000000000..2c8aa2e43d7 --- /dev/null +++ b/tests/integration/targets/ec2_instance_security_group/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: security_groups diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/security_group.yml b/tests/integration/targets/ec2_instance_security_group/tasks/main.yml similarity index 92% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/security_group.yml rename to tests/integration/targets/ec2_instance_security_group/tasks/main.yml index ad76a5edb72..47b1c963e39 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/security_group.yml +++ b/tests/integration/targets/ec2_instance_security_group/tasks/main.yml @@ -1,4 +1,10 @@ -- block: +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: - name: "New instance with 2 security groups" ec2_instance: name: "{{ resource_prefix }}-test-security-groups" diff --git a/tests/integration/targets/ec2_instance_state_config_updates/aliases b/tests/integration/targets/ec2_instance_state_config_updates/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_state_config_updates/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_state_config_updates/defaults/main.yml b/tests/integration/targets/ec2_instance_state_config_updates/defaults/main.yml new file mode 100644 index 00000000000..6cc33af3796 --- /dev/null +++ b/tests/integration/targets/ec2_instance_state_config_updates/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-state-config-updates' diff --git a/tests/integration/targets/ec2_instance_state_config_updates/meta/main.yml b/tests/integration/targets/ec2_instance_state_config_updates/meta/main.yml new file mode 100644 index 00000000000..c9fdd98d9df --- /dev/null +++ b/tests/integration/targets/ec2_instance_state_config_updates/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: state_config_updates diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/state_config_updates.yml b/tests/integration/targets/ec2_instance_state_config_updates/tasks/main.yml similarity index 91% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/state_config_updates.yml rename to tests/integration/targets/ec2_instance_state_config_updates/tasks/main.yml index 9592b55a654..0d5d5a5c2e2 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/state_config_updates.yml +++ b/tests/integration/targets/ec2_instance_state_config_updates/tasks/main.yml @@ -2,7 +2,13 @@ # are updated correctly when the instance has different states, and also when # changing the state of an instance. # https://github.com/ansible-collections/community.aws/issues/16 -- block: +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: - name: "Make instance with sg and termination protection enabled" ec2_instance: state: running @@ -125,22 +131,3 @@ - '"start_failed" in change_params_start_result' - change_params_start_result.instances[0].security_groups[0].group_id == "{{ sg.group_id }}" - change_params_start_result.changes[0].DisableApiTermination.Value == False - - always: - - - name: Set termination protection to false (so we can terminate instance) (cleanup) - ec2_instance: - filters: - tag:TestId: "{{ ec2_instance_tag_TestId }}" - termination_protection: False - ignore_errors: yes - - - name: Terminate instance - ec2_instance: - filters: - tag:TestId: "{{ ec2_instance_tag_TestId }}" - state: absent - wait: False - ignore_errors: yes - - - include_tasks: env_cleanup.yml diff --git a/tests/integration/targets/ec2_instance_tags_and_vpc_settings/aliases b/tests/integration/targets/ec2_instance_tags_and_vpc_settings/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_tags_and_vpc_settings/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_tags_and_vpc_settings/defaults/main.yml b/tests/integration/targets/ec2_instance_tags_and_vpc_settings/defaults/main.yml new file mode 100644 index 00000000000..8e81c2fe8db --- /dev/null +++ b/tests/integration/targets/ec2_instance_tags_and_vpc_settings/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-tags-vpc' diff --git a/tests/integration/targets/ec2_instance_tags_and_vpc_settings/meta/main.yml b/tests/integration/targets/ec2_instance_tags_and_vpc_settings/meta/main.yml new file mode 100644 index 00000000000..3a35100658e --- /dev/null +++ b/tests/integration/targets/ec2_instance_tags_and_vpc_settings/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: tags_and_vpc diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/tags_and_vpc_settings.yml b/tests/integration/targets/ec2_instance_tags_and_vpc_settings/tasks/main.yml similarity index 92% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/tags_and_vpc_settings.yml rename to tests/integration/targets/ec2_instance_tags_and_vpc_settings/tasks/main.yml index 2bde4b5895e..71551ef2935 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/tags_and_vpc_settings.yml +++ b/tests/integration/targets/ec2_instance_tags_and_vpc_settings/tasks/main.yml @@ -1,4 +1,10 @@ -- block: +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: - name: "Make instance in the testing subnet created in the test VPC" ec2_instance: state: present @@ -171,22 +177,3 @@ that: - _purge_tags.instances[0].tags | length == 1 - _purge_tags.instances[0].tags.Name.startswith(resource_prefix) - - - name: "Terminate instance" - ec2_instance: - state: absent - filters: - "tag:Name": "{{ resource_prefix }}-test-basic-vpc-create" - wait: false - register: result - - assert: - that: result.changed - - always: - - name: "Terminate tags_and_vpc_settings instances" - ec2_instance: - state: absent - filters: - "tag:TestId": "{{ ec2_instance_tag_TestId }}" - wait: yes - ignore_errors: yes diff --git a/tests/integration/targets/ec2_instance_termination_protection/aliases b/tests/integration/targets/ec2_instance_termination_protection/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_termination_protection/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_termination_protection/defaults/main.yml b/tests/integration/targets/ec2_instance_termination_protection/defaults/main.yml new file mode 100644 index 00000000000..129821f2ef7 --- /dev/null +++ b/tests/integration/targets/ec2_instance_termination_protection/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-temination' diff --git a/tests/integration/targets/ec2_instance_termination_protection/meta/main.yml b/tests/integration/targets/ec2_instance_termination_protection/meta/main.yml new file mode 100644 index 00000000000..b75f3dd58a1 --- /dev/null +++ b/tests/integration/targets/ec2_instance_termination_protection/meta/main.yml @@ -0,0 +1,6 @@ +# this just makes sure they're in the right place +dependencies: +- role: setup_ec2_facts +- role: setup_ec2_instance_env + vars: + ec2_instance_test_name: terminaion_protection diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/termination_protection.yml b/tests/integration/targets/ec2_instance_termination_protection/tasks/main.yml similarity index 95% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/termination_protection.yml rename to tests/integration/targets/ec2_instance_termination_protection/tasks/main.yml index 3e86e634482..4c888592b2f 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/termination_protection.yml +++ b/tests/integration/targets/ec2_instance_termination_protection/tasks/main.yml @@ -1,4 +1,10 @@ -- block: +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: - name: Create instance with termination protection (check mode) ec2_instance: name: "{{ resource_prefix }}-termination-protection" @@ -242,20 +248,3 @@ filters: tag:TestId: "{{ resource_prefix }}" state: absent - - always: - - - name: Set termination protection to false (so we can terminate instance) (cleanup) - ec2_instance: - filters: - tag:TestId: "{{ resource_prefix }}" - termination_protection: false - ignore_errors: yes - - - name: Terminate instance - ec2_instance: - filters: - tag:TestId: "{{ resource_prefix }}" - state: absent - wait: false - ignore_errors: yes diff --git a/tests/integration/targets/ec2_instance_uptime/aliases b/tests/integration/targets/ec2_instance_uptime/aliases new file mode 100644 index 00000000000..5f0924388a9 --- /dev/null +++ b/tests/integration/targets/ec2_instance_uptime/aliases @@ -0,0 +1,5 @@ + +cloud/aws +ec2_instance_info +ec2_instance + diff --git a/tests/integration/targets/ec2_instance_uptime/defaults/main.yml b/tests/integration/targets/ec2_instance_uptime/defaults/main.yml new file mode 100644 index 00000000000..73045da6b82 --- /dev/null +++ b/tests/integration/targets/ec2_instance_uptime/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ec2_instance +ec2_instance_type: 't3.micro' +ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-uptime' diff --git a/tests/integration/targets/ec2_instance/meta/main.yml b/tests/integration/targets/ec2_instance_uptime/meta/main.yml similarity index 59% rename from tests/integration/targets/ec2_instance/meta/main.yml rename to tests/integration/targets/ec2_instance_uptime/meta/main.yml index b907b87853a..6651aa834c0 100644 --- a/tests/integration/targets/ec2_instance/meta/main.yml +++ b/tests/integration/targets/ec2_instance_uptime/meta/main.yml @@ -1,6 +1,6 @@ # this just makes sure they're in the right place dependencies: - role: setup_ec2_facts -- role: setup_botocore_pip +- role: setup_ec2_instance_env vars: - boto3_version: "1.20.30" + ec2_instance_test_name: uptime diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/uptime.yml b/tests/integration/targets/ec2_instance_uptime/tasks/main.yml similarity index 87% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/uptime.yml rename to tests/integration/targets/ec2_instance_uptime/tasks/main.yml index 7358bc71d5f..6f7cf38dd5d 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/uptime.yml +++ b/tests/integration/targets/ec2_instance_uptime/tasks/main.yml @@ -1,5 +1,11 @@ --- -- block: +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: - name: "create t3.nano instance" ec2_instance: name: "{{ resource_prefix }}-test-uptime" @@ -55,12 +61,3 @@ assert: that: - "{{ instance_facts.instances | length }} == 1" - - always: - - name: "Terminate instances" - ec2_instance: - state: absent - filters: - "tag:TestId": "{{ ec2_instance_tag_TestId }}" - wait: yes - ignore_errors: yes diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/defaults/main.yml b/tests/integration/targets/setup_ec2_instance_env/defaults/main.yml similarity index 62% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/defaults/main.yml rename to tests/integration/targets/setup_ec2_instance_env/defaults/main.yml index e137e28de89..b3858247831 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/defaults/main.yml +++ b/tests/integration/targets/setup_ec2_instance_env/defaults/main.yml @@ -4,8 +4,11 @@ ec2_instance_owner: 'integration-run-{{ resource_prefix }}' ec2_instance_type: 't3.micro' ec2_instance_tag_TestId: '{{ resource_prefix }}-{{ inventory_hostname }}' -vpc_name: '{{ resource_prefix }}-vpc' -vpc_seed: '{{ resource_prefix }}' +ec2_instance_test_name: 'ec2_instance' + +vpc_name: '{{ resource_prefix }}-{{ ec2_instance_test_name }}' +vpc_seed: '{{ resource_prefix }}-{{ ec2_instance_test_name }}' + vpc_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.0.0/16' subnet_a_az: '{{ ec2_availability_zone_names[0] }}' @@ -14,8 +17,3 @@ subnet_a_startswith: '10.{{ 256 | random(seed=vpc_seed) }}.32.' subnet_b_az: '{{ ec2_availability_zone_names[1] }}' subnet_b_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.33.0/24' subnet_b_startswith: '10.{{ 256 | random(seed=vpc_seed) }}.33.' - -first_iam_role: "ansible-test-sts-{{ resource_prefix | hash('md5') }}-test-policy" -second_iam_role: "ansible-test-sts-{{ resource_prefix | hash('md5') }}-test-policy-2" -# Zuul resource prefixes are very long, and IAM roles can only be 64 characters -unique_id: "{{ resource_prefix | hash('md5') }}" diff --git a/tests/integration/targets/setup_ec2_instance_env/handlers/main.yml b/tests/integration/targets/setup_ec2_instance_env/handlers/main.yml new file mode 100644 index 00000000000..b8dee611d09 --- /dev/null +++ b/tests/integration/targets/setup_ec2_instance_env/handlers/main.yml @@ -0,0 +1,2 @@ +- name: 'Delete ec2_instance environment' + include_tasks: cleanup.yml diff --git a/tests/integration/targets/setup_ec2_instance_env/meta/main.yml b/tests/integration/targets/setup_ec2_instance_env/meta/main.yml new file mode 100644 index 00000000000..32cf5dda7ed --- /dev/null +++ b/tests/integration/targets/setup_ec2_instance_env/meta/main.yml @@ -0,0 +1 @@ +dependencies: [] diff --git a/tests/integration/targets/setup_ec2_instance_env/tasks/cleanup.yml b/tests/integration/targets/setup_ec2_instance_env/tasks/cleanup.yml new file mode 100644 index 00000000000..0a0aa1eed76 --- /dev/null +++ b/tests/integration/targets/setup_ec2_instance_env/tasks/cleanup.yml @@ -0,0 +1,118 @@ +- module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: + - name: Set termination protection to false (so we can terminate instance) (cleanup) + ec2_instance: + filters: + instance-state-name: ['pending', 'running', 'stopping', 'stopped'] + vpc-id: '{{ testing_vpc.vpc.id }}' + termination_protection: false + ignore_errors: yes + + - name: "(Cleanup) Find all remaining Instances" + ec2_instance_info: + filters: + vpc-id: '{{ testing_vpc.vpc.id }}' + instance-state-name: ['pending', 'running', 'shutting-down', 'stopping', 'stopped'] + register: instances + + - name: "(Cleanup) Remove Instances (start)" + ec2_instance: + state: absent + instance_ids: '{{ item.instance_id }}' + wait: no + ignore_errors: yes + loop: '{{ instances.instances }}' + + - name: "(Cleanup) Remove Instances (wait for completion)" + ec2_instance: + state: absent + instance_ids: '{{ item.instance_id }}' + filters: + instance-state-name: ['pending', 'running', 'shutting-down', 'stopping', 'stopped'] + vpc-id: '{{ testing_vpc.vpc.id }}' + wait: yes + ignore_errors: yes + loop: '{{ instances.instances }}' + + - name: "(Cleanup) Find all remaining ENIs" + ec2_eni_info: + filters: + vpc-id: "{{ testing_vpc.vpc.id }}" + register: enis + + - name: "(Cleanup) delete all ENIs" + ec2_eni: + state: absent + eni_id: "{{ item.id }}" + register: eni_removed + until: eni_removed is not failed + with_items: "{{ enis.network_interfaces }}" + ignore_errors: yes + retries: 10 + + - name: "(Cleanup) Find all remaining Security Groups" + ec2_security_group_info: + filters: + vpc-id: '{{ testing_vpc.vpc.id }}' + register: security_groups + + - name: "(Cleanup) Remove the security group rules" + ec2_security_group: + state: present + name: '{{ item.group_name }}' + description: '{{ item.description }}' + vpc_id: '{{ testing_vpc.vpc.id }}' + rules: [] + egress_rules: [] + loop: '{{ security_groups.security_groups }}' + register: sg_removed + until: sg_removed is not failed + ignore_errors: yes + retries: 10 + + - name: "(Cleanup) Remove the security groups" + ec2_security_group: + state: absent + group_id: '{{ item.group_id }}' + loop: '{{ security_groups.security_groups }}' + when: + - item.group_name != 'default' + register: sg_removed + until: sg_removed is not failed + ignore_errors: yes + retries: 10 + + - name: "(Cleanup) Find all remaining Subnets" + ec2_vpc_subnet_info: + filters: + vpc-id: '{{ testing_vpc.vpc.id }}' + register: subnets + + - name: "(Cleanup) Remove subnets" + ec2_vpc_subnet: + state: absent + vpc_id: "{{ testing_vpc.vpc.id }}" + cidr: "{{ item.cidr_block }}" + register: removed + loop: '{{ subnets.subnets }}' + until: removed is not failed + ignore_errors: yes + retries: 10 + + - name: "(Cleanup) Remove the VPC" + ec2_vpc_net: + state: absent + name: "{{ vpc_name }}" + cidr_block: "{{ vpc_cidr }}" + tags: + Name: Ansible Testing VPC + tenancy: default + register: removed + until: removed is not failed + ignore_errors: yes + retries: 10 diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/env_setup.yml b/tests/integration/targets/setup_ec2_instance_env/tasks/main.yml similarity index 86% rename from tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/env_setup.yml rename to tests/integration/targets/setup_ec2_instance_env/tasks/main.yml index 4ec8bc49c06..3fbf5ecb567 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/env_setup.yml +++ b/tests/integration/targets/setup_ec2_instance_env/tasks/main.yml @@ -1,4 +1,10 @@ - run_once: '{{ setup_run_once | default("no") | bool }}' + module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" block: - name: "Create VPC for use in testing" ec2_vpc_net: @@ -9,6 +15,8 @@ Name: Ansible ec2_instance Testing VPC tenancy: default register: testing_vpc + notify: + - 'Delete ec2_instance environment' - name: "Create default subnet in zone A" ec2_vpc_subnet: