diff --git a/changelogs/fragments/migrate_ec2_placement_group.yml b/changelogs/fragments/migrate_ec2_placement_group.yml new file mode 100644 index 00000000000..3b273a98983 --- /dev/null +++ b/changelogs/fragments/migrate_ec2_placement_group.yml @@ -0,0 +1,8 @@ +--- +breaking_changes: + - ec2_placement_group - The module has been migrated from the ``community.aws`` + collection. Playbooks using the Fully Qualified Collection Name for this module + should be updated to use ``amazon.aws.ec2_placement_group``. + - ec2_placement_group_info - The module has been migrated from the ``community.aws`` + collection. Playbooks using the Fully Qualified Collection Name for this module + should be updated to use ``amazon.aws.ec2_placement_group_info``. diff --git a/meta/runtime.yml b/meta/runtime.yml index 306eee289fe..23729367a4d 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -106,8 +106,6 @@ action_groups: - ec2_lc_find - ec2_lc_info - ec2_metric_alarm - - ec2_placement_group - - ec2_placement_group_info - ec2_scaling_policy - ec2_snapshot_copy - ec2_transit_gateway @@ -530,6 +528,10 @@ plugin_routing: redirect: amazon.aws.ec2_vpc_peer ec2_vpc_peering_info: redirect: amazon.aws.ec2_vpc_peering_info + ec2_placement_group: + redirect: amazon.aws.ec2_placement_group + ec2_placement_group_info: + redirect: amazon.aws.ec2_placement_group_info module_utils: route53: redirect: amazon.aws.route53 diff --git a/plugins/modules/ec2_placement_group.py b/plugins/modules/ec2_placement_group.py deleted file mode 100644 index 1a38252ac97..00000000000 --- a/plugins/modules/ec2_placement_group.py +++ /dev/null @@ -1,247 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# Copyright (c) 2017 Ansible Project -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -DOCUMENTATION = r""" ---- -module: ec2_placement_group -version_added: 1.0.0 -short_description: Create or delete an EC2 Placement Group -description: - - Create an EC2 Placement Group; if the placement group already exists, - nothing is done. Or, delete an existing placement group. If the placement - group is absent, do nothing. See also - U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/placement-groups.html) -author: - - "Brad Macpherson (@iiibrad)" -options: - name: - description: - - The name for the placement group. - required: true - type: str - partition_count: - description: - - The number of partitions. - - Valid only when O(strategy) is set to V(partition). - - Must be a value between V(1) and V(7). - type: int - version_added: 3.1.0 - state: - description: - - Create or delete placement group. - default: present - choices: [ 'present', 'absent' ] - type: str - strategy: - description: - - Placement group strategy. Cluster will cluster instances into a - low-latency group in a single Availability Zone, while Spread spreads - instances across underlying hardware. - default: cluster - choices: [ 'cluster', 'spread', 'partition' ] - type: str - tags: - description: - - A dict of key value pairs to associate with the placement group - type: dict - version_added: 8.1.0 -extends_documentation_fragment: - - amazon.aws.common.modules - - amazon.aws.region.modules - - amazon.aws.boto3 -""" - -EXAMPLES = r""" -# Note: These examples do not set authentication details, see the AWS Guide -# for details. - -- name: Create a placement group. - community.aws.ec2_placement_group: - name: my-cluster - state: present - -- name: Create a Spread placement group. - community.aws.ec2_placement_group: - name: my-cluster - state: present - strategy: spread - -- name: Create a Partition strategy placement group. - community.aws.ec2_placement_group: - name: my-cluster - state: present - strategy: partition - partition_count: 3 - -- name: Delete a placement group. - community.aws.ec2_placement_group: - name: my-cluster - state: absent -""" - -RETURN = r""" -placement_group: - description: Placement group attributes - returned: when state != absent - type: dict - contains: - group_arn: - description: Placement Group ARN. - type: str - returned: always - sample: "arn:aws:ec2:us-east-1:123456789012:placement-group" - group_id: - description: Placement Group Id. - type: str - returned: always - sample: "pg-123456789012" - name: - description: Placement Group name. - type: str - returned: always - sample: "my-cluster" - partition_count: - description: Partition Count. - type: str - returned: If applicable - sample: "my-cluster" - state: - description: Placement Groupt state. - type: str - returned: If applicable - sample: "available" - strategy: - description: Placement Group strategy. - type: str - returned: If applicable - sample: "cluster" - tags: - description: Tags associated with the placement group. - type: dict - returned: If applicable - version_added: 8.1.0 - sample: - tags: - some: value1 - other: value2 -""" - -from typing import Any -from typing import Dict - -from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict - -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import create_ec2_placement_group -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import delete_ec2_placement_group -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_ec2_placement_groups -from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict -from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications - -from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule - - -def search_placement_group(connection, name: str) -> Dict[str, Any]: - """ - Check if a placement group exists. - """ - response = describe_ec2_placement_groups(connection, Filters=[{"Name": "group-name", "Values": [name]}]) - - if len(response) != 1: - return None - else: - return format_placement_group_information(response[0]) - - -def format_placement_group_information(response: Dict[str, Any]) -> Dict[str, Any]: - """ - Format placement group information - """ - - response = camel_dict_to_snake_dict(response, ignore_list=["Tags"]) - if "tags" in response: - response["tags"] = boto3_tag_list_to_ansible_dict(response.get("tags", [])) - response["name"] = response["group_name"] - return response - - -def create_placement_group(connection, module: AnsibleAWSModule) -> None: - name = module.params.get("name") - strategy = module.params.get("strategy") - tags = module.params.get("tags") - partition_count = module.params.get("partition_count") - - if strategy != "partition" and partition_count: - module.fail_json(msg="'partition_count' can only be set when strategy is set to 'partition'.") - - params = {} - params["GroupName"] = name - params["Strategy"] = strategy - if tags: - params["TagSpecifications"] = boto3_tag_specifications(tags, types=["placement-group"]) - if partition_count: - params["PartitionCount"] = partition_count - if module.check_mode: - module.exit_json( - changed=True, - placement_group={ - "name": name, - "strategy": strategy, - "tags": tags, - }, - msg="EC2 placement group would be created if not in check mode", - ) - - response = create_ec2_placement_group(connection, **params) - module.exit_json(changed=True, placement_group=format_placement_group_information(response)) - - -def delete_placement_group(connection, module: AnsibleAWSModule) -> None: - if module.check_mode: - module.exit_json(changed=True, msg="VPC would be deleted if not in check mode") - name = module.params.get("name") - delete_ec2_placement_group(connection, name) - module.exit_json(changed=True) - - -def main(): - argument_spec = dict( - name=dict(required=True, type="str"), - partition_count=dict(type="int"), - state=dict(default="present", choices=["present", "absent"]), - strategy=dict(default="cluster", choices=["cluster", "spread", "partition"]), - tags=dict(type="dict"), - ) - - module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) - - connection = module.client("ec2") - - state = module.params.get("state") - name = module.params.get("name") - placement_group = search_placement_group(connection, name) - - if state == "present": - if placement_group is None: - create_placement_group(connection, module) - else: - strategy = module.params.get("strategy") - if placement_group["strategy"] == strategy: - module.exit_json(changed=False, placement_group=placement_group) - else: - name = module.params.get("name") - module.fail_json( - msg=f"Placement group '{name}' exists, can't change strategy from '{placement_group['strategy']}' to '{strategy}'" - ) - - elif state == "absent": - if placement_group is None: - module.exit_json(changed=False) - else: - delete_placement_group(connection, module) - - -if __name__ == "__main__": - main() diff --git a/plugins/modules/ec2_placement_group_info.py b/plugins/modules/ec2_placement_group_info.py deleted file mode 100644 index 8c67e2b5fa4..00000000000 --- a/plugins/modules/ec2_placement_group_info.py +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# Copyright (c) 2017 Ansible Project -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -DOCUMENTATION = r""" ---- -module: ec2_placement_group_info -version_added: 1.0.0 -short_description: List EC2 Placement Group(s) details -description: - - List details of EC2 Placement Group(s). -author: - - "Brad Macpherson (@iiibrad)" -options: - names: - description: - - A list of names to filter on. If a listed group does not exist, there - will be no corresponding entry in the result; no error will be raised. - type: list - elements: str - required: false - default: [] -extends_documentation_fragment: - - amazon.aws.common.modules - - amazon.aws.region.modules - - amazon.aws.boto3 -""" - -EXAMPLES = r""" -# Note: These examples do not set authentication details or the AWS region, -# see the AWS Guide for details. - -- name: List all placement groups. - community.aws.ec2_placement_group_info: - register: all_ec2_placement_groups - -- name: List two placement groups. - community.aws.ec2_placement_group_info: - names: - - my-cluster - - my-other-cluster - register: specific_ec2_placement_groups - -- ansible.builtin.debug: - msg: > - {{ specific_ec2_placement_groups | json_query("[?name=='my-cluster']") }} -""" - - -RETURN = r""" -placement_groups: - description: Placement group attributes - returned: always - type: complex - contains: - name: - description: PG name - type: str - sample: "my-cluster" - state: - description: PG state - type: str - sample: "available" - strategy: - description: PG strategy - type: str - sample: "cluster" - tags: - description: Tags associated with the placement group - type: dict - version_added: 8.1.0 - sample: - tags: - some: value1 - other: value2 -""" - -from typing import Any -from typing import Dict -from typing import List - -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_ec2_placement_groups -from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict - - -def get_placement_groups_details(connection, names: List) -> Dict[str, Any]: - params = {} - if len(names) > 0: - params["Filters"] = [ - { - "Name": "group-name", - "Values": names, - } - ] - response = describe_ec2_placement_groups(connection, **params) - - results = [] - for placement_group in response: - results.append( - { - "name": placement_group["GroupName"], - "state": placement_group["State"], - "strategy": placement_group["Strategy"], - "tags": boto3_tag_list_to_ansible_dict(placement_group.get("Tags")), - } - ) - return results - - -def main(): - argument_spec = dict( - names=dict(type="list", default=[], elements="str"), - ) - - module = AnsibleAWSModule( - argument_spec=argument_spec, - supports_check_mode=True, - ) - - connection = module.client("ec2") - names = module.params.get("names") - - placement_groups = get_placement_groups_details(connection, names) - module.exit_json(changed=False, placement_groups=placement_groups) - - -if __name__ == "__main__": - main() diff --git a/tests/integration/targets/ec2_placement_group/aliases b/tests/integration/targets/ec2_placement_group/aliases deleted file mode 100644 index c6944e7b949..00000000000 --- a/tests/integration/targets/ec2_placement_group/aliases +++ /dev/null @@ -1,3 +0,0 @@ -cloud/aws - -ec2_placement_group_info diff --git a/tests/integration/targets/ec2_placement_group/defaults/main.yml b/tests/integration/targets/ec2_placement_group/defaults/main.yml deleted file mode 100644 index ed97d539c09..00000000000 --- a/tests/integration/targets/ec2_placement_group/defaults/main.yml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/tests/integration/targets/ec2_placement_group/meta/main.yml b/tests/integration/targets/ec2_placement_group/meta/main.yml deleted file mode 100644 index ed97d539c09..00000000000 --- a/tests/integration/targets/ec2_placement_group/meta/main.yml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/tests/integration/targets/ec2_placement_group/tasks/env_cleanup.yml b/tests/integration/targets/ec2_placement_group/tasks/env_cleanup.yml deleted file mode 100644 index be84fe8f17a..00000000000 --- a/tests/integration/targets/ec2_placement_group/tasks/env_cleanup.yml +++ /dev/null @@ -1,94 +0,0 @@ -- name: Remove any instances in the test VPC - amazon.aws.ec2_instance: - filters: - vpc_id: "{{ testing_vpc.vpc.id }}" - state: absent - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - -- name: Get ENIs - amazon.aws.ec2_eni_info: - filters: - vpc-id: "{{ testing_vpc.vpc.id }}" - register: enis - -- name: Delete all ENIs - amazon.aws.ec2_eni: - eni_id: "{{ item.id }}" - state: absent - until: removed is not failed - with_items: "{{ enis.network_interfaces }}" - ignore_errors: yes - retries: 10 - -- name: Remove the security group - amazon.aws.ec2_security_group: - name: "{{ resource_prefix }}-sg" - 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 routing rules - amazon.aws.ec2_vpc_route_table: - state: absent - vpc_id: "{{ testing_vpc.vpc.id }}" - tags: - created: "{{ resource_prefix }}-route" - routes: - - dest: 0.0.0.0/0 - gateway_id: "{{ igw.gateway_id }}" - subnets: - - "{{ testing_subnet_a.subnet.id }}" - - "{{ testing_subnet_b.subnet.id }}" - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - -- name: Remove internet gateway - amazon.aws.ec2_vpc_igw: - vpc_id: "{{ testing_vpc.vpc.id }}" - state: absent - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - -- name: Remove subnet A - amazon.aws.ec2_vpc_subnet: - state: absent - vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.32.0/24 - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - -- name: Remove subnet B - amazon.aws.ec2_vpc_subnet: - state: absent - vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.33.0/24 - register: removed - until: removed is not failed - ignore_errors: yes - retries: 10 - -- name: Remove the VPC - amazon.aws.ec2_vpc_net: - name: "{{ resource_prefix }}-vpc" - cidr_block: 10.22.32.0/23 - state: absent - 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_placement_group/tasks/env_setup.yml b/tests/integration/targets/ec2_placement_group/tasks/env_setup.yml deleted file mode 100644 index 54fa62a35db..00000000000 --- a/tests/integration/targets/ec2_placement_group/tasks/env_setup.yml +++ /dev/null @@ -1,64 +0,0 @@ -- name: Create VPC for use in testing - amazon.aws.ec2_vpc_net: - name: "{{ resource_prefix }}-vpc" - cidr_block: 10.22.32.0/23 - tags: - Name: Ansible ec2_lc Testing VPC - tenancy: default - register: testing_vpc - -- name: Create internet gateway for use in testing - amazon.aws.ec2_vpc_igw: - vpc_id: "{{ testing_vpc.vpc.id }}" - state: present - tags: - Name: Ansible ec2_lc Testing gateway - register: igw - -- name: Create default subnet in zone A - amazon.aws.ec2_vpc_subnet: - state: present - vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.32.0/24 - az: "{{ aws_region }}a" - resource_tags: - Name: "{{ resource_prefix }}-subnet-a" - register: testing_subnet_a - -- name: Create secondary subnet in zone B - amazon.aws.ec2_vpc_subnet: - state: present - vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.33.0/24 - az: "{{ aws_region }}b" - resource_tags: - Name: "{{ resource_prefix }}-subnet-b" - register: testing_subnet_b - -- name: Create routing rules - amazon.aws.ec2_vpc_route_table: - vpc_id: "{{ testing_vpc.vpc.id }}" - tags: - created: "{{ resource_prefix }}-route" - routes: - - dest: 0.0.0.0/0 - gateway_id: "{{ igw.gateway_id }}" - subnets: - - "{{ testing_subnet_a.subnet.id }}" - - "{{ testing_subnet_b.subnet.id }}" - -- name: Create a security group with the vpc - amazon.aws.ec2_security_group: - name: "{{ resource_prefix }}-sg" - description: a security group for ansible tests - vpc_id: "{{ testing_vpc.vpc.id }}" - rules: - - proto: tcp - from_port: 22 - to_port: 22 - cidr_ip: 0.0.0.0/0 - - proto: tcp - from_port: 80 - to_port: 80 - cidr_ip: 0.0.0.0/0 - register: sg diff --git a/tests/integration/targets/ec2_placement_group/tasks/main.yml b/tests/integration/targets/ec2_placement_group/tasks/main.yml deleted file mode 100644 index 130f347db97..00000000000 --- a/tests/integration/targets/ec2_placement_group/tasks/main.yml +++ /dev/null @@ -1,566 +0,0 @@ -- name: run ec2_placement_group tests - module_defaults: - group/aws: - access_key: "{{ aws_access_key }}" - secret_key: "{{ aws_secret_key }}" - session_token: "{{ security_token | default(omit) }}" - region: "{{ aws_region }}" - collections: - - amazon.aws - vars: - placement_group_names: [] - - block: - - - name: Set up environment for testing. - include_tasks: env_setup.yml - - - name: Create a placement group 1 - check_mode - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg1' - state: present - check_mode: true - register: pg_1_create_check_mode - - - name: Assert that placement group data is returned (check mode) - ansible.builtin.assert: - that: - - pg_1_create_check_mode is changed - - pg_1_create_check_mode.placement_group.name == resource_prefix ~ '-pg1' - - - name: Create a placement group 1 - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg1' - state: present - register: pg_1_create - - - ansible.builtin.set_fact: - placement_group_names: "{{ placement_group_names + [pg_1_create.placement_group.name] }}" - - - name: Assert that placement group is created - ansible.builtin.assert: - that: - - pg_1_create is changed - - pg_1_create.placement_group.name == resource_prefix ~ '-pg1' - - pg_1_create.placement_group.state == "available" - - '"ec2:CreatePlacementGroup" in pg_1_create.resource_actions' - - - name: Gather information about placement group 1 - community.aws.ec2_placement_group_info: - names: - - '{{ resource_prefix }}-pg1' - register: pg_1_info_result - - - name: Assert that placement group is created - ansible.builtin.assert: - that: - - pg_1_info_result is not changed - - pg_1_info_result.placement_groups[0].name == resource_prefix ~ '-pg1' - - pg_1_info_result.placement_groups[0].state == "available" - - pg_1_info_result.placement_groups[0].strategy == "cluster" - - '"ec2:DescribePlacementGroups" in pg_1_info_result.resource_actions' - - - name: Create a placement group 1 - Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg1' - state: present - register: pg_1_create - - - name: Assert that placement group is not created (idempotent) - ansible.builtin.assert: - that: - - pg_1_create is not changed - - pg_1_create.placement_group.name == resource_prefix ~ '-pg1' - - pg_1_create.placement_group.state == "available" - - '"ec2:CreatePlacementGroup" not in pg_1_create.resource_actions' - - - name: Create a placement group 1 - check_mode Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg1' - state: present - check_mode: true - register: pg_1_create_check_mode_idem - - - name: Assert that placement group is not created (idempotent - check_mode) - ansible.builtin.assert: - that: - - pg_1_create_check_mode_idem is not changed - - pg_1_create_check_mode_idem.placement_group.name == resource_prefix ~ '-pg1' - - pg_1_create_check_mode_idem.placement_group.state == "available" - - - name: Create a placement group 2 - check_mode - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg2' - state: present - strategy: spread - check_mode: true - register: pg_2_create_check_mode - - - name: Assert that placement group is created - ansible.builtin.assert: - that: - - pg_2_create_check_mode is changed - - pg_2_create_check_mode.placement_group.name == resource_prefix ~ '-pg2' - - - name: Create a placement group 2 with spread strategy - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg2' - state: present - strategy: spread - register: pg_2_create - - - name: Assert that placement group is created - ansible.builtin.assert: - that: - - pg_2_create is changed - - pg_2_create.placement_group.name == resource_prefix ~ '-pg2' - - pg_2_create.placement_group.state == "available" - - '"ec2:CreatePlacementGroup" in pg_2_create.resource_actions' - - - ansible.builtin.set_fact: - placement_group_names: "{{ placement_group_names + [pg_2_create.placement_group.name] }}" - - - name: Gather information about placement group 2 - community.aws.ec2_placement_group_info: - names: - - '{{ resource_prefix }}-pg2' - register: pg_2_info_result - - - name: Assert that placement group is created - ansible.builtin.assert: - that: - - pg_2_info_result is not changed - - pg_2_info_result.placement_groups[0].name == resource_prefix ~ '-pg2' - - pg_2_info_result.placement_groups[0].state == "available" - - pg_2_info_result.placement_groups[0].strategy == "spread" - - '"ec2:DescribePlacementGroups" in pg_2_info_result.resource_actions' - - - name: Create a placement group 2 with spread strategy - Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg2' - state: present - strategy: spread - register: pg_2_create - - - name: Assert that placement group exists (idempotent) - ansible.builtin.assert: - that: - - pg_2_create is not changed - - pg_2_create.placement_group.name == resource_prefix ~ '-pg2' - - pg_2_create.placement_group.state == "available" - - '"ec2:CreatePlacementGroup" not in pg_2_create.resource_actions' - - - name: Create a placement group 2 - check_mode Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg2' - state: present - strategy: spread - check_mode: true - register: pg_2_create_check_mode_idem - - - name: Assert that placement group exists (idempotent - check_mode) - ansible.builtin.assert: - that: - - pg_2_create_check_mode_idem is not changed - - pg_2_create_check_mode_idem.placement_group.name == resource_prefix ~ '-pg2' - - pg_2_create_check_mode_idem.placement_group.state == "available" - - - name: Create a placement group 3 - check_mode - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg3' - state: present - strategy: partition - partition_count: 4 - check_mode: true - register: pg_3_create_check_mode - - - name: Assert that placement group exists - ansible.builtin.assert: - that: - - pg_3_create_check_mode is changed - - pg_3_create_check_mode.placement_group.name == resource_prefix ~ '-pg3' - - - name: Create a placement group 3 with Partition strategy - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg3' - state: present - strategy: partition - partition_count: 4 - register: pg_3_create - - - name: Assert that placement group exists - ansible.builtin.assert: - that: - - pg_3_create is changed - - pg_3_create.placement_group.name == resource_prefix ~ '-pg3' - - pg_3_create.placement_group.state == "available" - - '"ec2:CreatePlacementGroup" in pg_3_create.resource_actions' - - - ansible.builtin.set_fact: - placement_group_names: "{{ placement_group_names + [pg_3_create.placement_group.name] }}" - - - - name: Gather information about placement group 3 - community.aws.ec2_placement_group_info: - names: - - '{{ resource_prefix }}-pg3' - register: pg_3_info_result - - - name: Assert that placement group exists - ansible.builtin.assert: - that: - - pg_3_info_result is not changed - - pg_3_info_result.placement_groups[0].name == resource_prefix ~ '-pg3' - - pg_3_info_result.placement_groups[0].state == "available" - - pg_3_info_result.placement_groups[0].strategy == "partition" - - '"ec2:DescribePlacementGroups" in pg_3_info_result.resource_actions' - - - name: Create a placement group 3 with Partition strategy - Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg3' - state: present - strategy: partition - partition_count: 4 - register: pg_3_create - - - name: Assert that placement group exists (idempotent) - ansible.builtin.assert: - that: - - pg_3_create is not changed - - pg_3_create.placement_group.name == resource_prefix ~ '-pg3' - - pg_3_create.placement_group.state == "available" - - '"ec2:CreatePlacementGroup" not in pg_3_create.resource_actions' - - - name: Create a placement group 3 - check_mode Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg3' - state: present - strategy: partition - partition_count: 4 - check_mode: true - register: pg_3_create_check_mode_idem - - - name: Assert that placement group exists (idempotent - check_mode) - ansible.builtin.assert: - that: - - pg_3_create_check_mode_idem is not changed - - pg_3_create_check_mode_idem.placement_group.name == resource_prefix ~ '-pg3' - - pg_3_create_check_mode_idem.placement_group.state == "available" - - - name: Create a placement group 4 with tags - check_mode - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg4' - state: present - strategy: cluster - tags: - foo: test1 - bar: test2 - check_mode: true - register: pg_4_create_check_mode - - - name: Assert that placement group exists (check-mode) - ansible.builtin.assert: - that: - - pg_4_create_check_mode is changed - - pg_4_create_check_mode.placement_group.name == resource_prefix ~ '-pg4' - - pg_4_create_check_mode.placement_group.tags.foo == "test1" - - pg_4_create_check_mode.placement_group.tags.bar == "test2" - - - name: Create a placement group 4 with tags - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg4' - state: present - strategy: cluster - tags: - foo: test1 - bar: test2 - register: pg_4_create - - - name: Assert that placement group exists - ansible.builtin.assert: - that: - - pg_4_create is changed - - pg_4_create.placement_group.name == resource_prefix ~ '-pg4' - - pg_4_create.placement_group.state == "available" - - pg_4_create.placement_group.tags.foo == "test1" - - pg_4_create.placement_group.tags.bar == "test2" - - '"ec2:CreatePlacementGroup" in pg_4_create.resource_actions' - - - ansible.builtin.set_fact: - placement_group_names: "{{ placement_group_names + [pg_4_create.placement_group.name] }}" - - - name: Gather information about placement group 4 - community.aws.ec2_placement_group_info: - names: - - '{{ resource_prefix }}-pg4' - register: pg_4_info_result - - - name: Assert that placement group exists - ansible.builtin.assert: - that: - - pg_4_info_result is not changed - - pg_4_info_result.placement_groups[0].name == resource_prefix ~ '-pg4' - - pg_4_info_result.placement_groups[0].state == "available" - - pg_4_info_result.placement_groups[0].strategy == "cluster" - - pg_4_info_result.placement_groups[0].tags.foo == "test1" - - pg_4_info_result.placement_groups[0].tags.bar == "test2" - - '"ec2:DescribePlacementGroups" in pg_4_info_result.resource_actions' - - - name: Create a placement group 4 with tags - Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg4' - state: present - strategy: cluster - tags: - foo: test1 - bar: test2 - register: pg_4_create - - - name: Assert that placement group exists (idempotent) - ansible.builtin.assert: - that: - - pg_4_create is not changed - - pg_4_create.placement_group.name == resource_prefix ~ '-pg4' - - pg_4_create.placement_group.state == "available" - - pg_4_create.placement_group.strategy == "cluster" - - pg_4_create.placement_group.tags.foo == "test1" - - pg_4_create.placement_group.tags.bar == "test2" - - '"ec2:CreatePlacementGroup" not in pg_4_create.resource_actions' - - - name: Create a placement group 4 with tags - check_mode Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg4' - state: present - strategy: cluster - tags: - foo: test1 - bar: test2 - check_mode: true - register: pg_4_create_check_mode_idem - - - name: Assert that placement group exists (idempotent - check-mode) - ansible.builtin.assert: - that: - - pg_4_create_check_mode_idem is not changed - - pg_4_create_check_mode_idem.placement_group.name == resource_prefix ~ '-pg4' - - pg_4_create_check_mode_idem.placement_group.state == "available" - - pg_4_create_check_mode_idem.placement_group.strategy == "cluster" - - pg_4_create_check_mode_idem.placement_group.tags.foo == "test1" - - pg_4_create_check_mode_idem.placement_group.tags.bar == "test2" - - - name: List all placement groups. - community.aws.ec2_placement_group_info: - register: all_ec2_placement_groups - -# Delete Placement Group ========================================== - - - name: Delete a placement group 1 - check_mode - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg1' - state: absent - check_mode: true - register: pg_1_delete_check_mode - ignore_errors: true - - - name: Assert check mode (check mode) - ansible.builtin.assert: - that: - - pg_1_delete_check_mode is changed - - - name: Delete a placement group 1 - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg1' - state: absent - register: pg_1_delete - - - name: Assert that deletion is successful - ansible.builtin.assert: - that: - - pg_1_delete is changed - - '"ec2:DeletePlacementGroup" in pg_1_delete.resource_actions' - - - name: Delete a placement group 1 - Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg1' - state: absent - register: pg_1_delete - - - name: Assert that there is no change - ansible.builtin.assert: - that: - - pg_1_delete is not changed - - '"ec2:DeletePlacementGroup" not in pg_1_delete.resource_actions' - - - name: Delete a placement group 1 - check_mode Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg1' - state: absent - check_mode: true - register: pg_1_delete_check_mode_idem - ignore_errors: true - - - name: Assert that there is no change - ansible.builtin.assert: - that: - - pg_1_delete_check_mode_idem is not changed - - - name: Delete a placement group 2 - check_mode - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg2' - state: absent - check_mode: true - register: pg_2_delete_check_mode - ignore_errors: true - - - name: Assert that check mode is successful - ansible.builtin.assert: - that: - - pg_2_delete_check_mode is changed - - - name: Delete a placement group 2 - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg2' - state: absent - register: pg_2_delete - - - name: Assert that there is change - ansible.builtin.assert: - that: - - pg_2_delete is changed - - '"ec2:DeletePlacementGroup" in pg_2_delete.resource_actions' - - - name: Delete a placement group 2 - Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg2' - state: absent - register: pg_2_delete - - - name: Assert that there is no change - ansible.builtin.assert: - that: - - pg_2_delete is not changed - - '"ec2:DeletePlacementGroup" not in pg_2_delete.resource_actions' - - - name: Delete a placement group 2 - check_mode Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg2' - state: absent - check_mode: true - register: pg_2_delete_check_mode_idem - ignore_errors: true - - - name: Assert that there is no change - ansible.builtin.assert: - that: - - pg_2_delete_check_mode_idem is not changed - - - name: Delete a placement group 3 - check_mode - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg3' - state: absent - check_mode: true - register: pg_3_delete_check_mode - ignore_errors: true - - - name: Assert that there is change - check mode - ansible.builtin.assert: - that: - - pg_3_delete_check_mode is changed - - - name: Delete a placement group 3 - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg3' - state: absent - register: pg_3_delete - - - name: Assert that there is change - ansible.builtin.assert: - that: - - pg_3_delete is changed - - '"ec2:DeletePlacementGroup" in pg_3_delete.resource_actions' - - - name: Delete a placement group 3 - Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg3' - state: absent - register: pg_3_delete - - - name: Assert that there is no change - ansible.builtin.assert: - that: - - pg_3_delete is not changed - - '"ec2:DeletePlacementGroup" not in pg_3_delete.resource_actions' - - - name: Delete a placement group 3 - check_mode Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg3' - state: absent - check_mode: true - register: pg_3_delete_check_mode_idem - ignore_errors: true - - - name: Assert that there is no change - ansible.builtin.assert: - that: - - pg_3_delete_check_mode_idem is not changed - - - name: Delete a placement group 4 - check_mode - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg4' - state: absent - check_mode: true - register: pg_4_delete_check_mode - ignore_errors: true - - - name: Assert that there is change check mode - ansible.builtin.assert: - that: - - pg_4_delete_check_mode is changed - - - - name: Delete a placement group 4 - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg4' - state: absent - register: pg_4_delete - - - name: Assert that there is change - ansible.builtin.assert: - that: - - pg_4_delete is changed - - '"ec2:DeletePlacementGroup" in pg_4_delete.resource_actions' - - - name: Delete a placement group 4 - Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg4' - state: absent - register: pg_4_delete - - - name: Assert that there is no change - ansible.builtin.assert: - that: - - pg_4_delete is not changed - - '"ec2:DeletePlacementGroup" not in pg_4_delete.resource_actions' - - - name: Delete a placement group 4 - check_mode Idempotency - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg4' - state: absent - check_mode: true - register: pg_4_delete_check_mode_idem - ignore_errors: true - - - name: Assert that there is no change - ansible.builtin.assert: - that: - - pg_4_delete_check_mode_idem is not changed - - always: - - - name: Make sure placement groups created during test are deleted - community.aws.ec2_placement_group: - name: '{{ item }}' - state: absent - with_items: '{{ placement_group_names }}' - - - include_tasks: env_cleanup.yml diff --git a/tests/integration/targets/ec2_placement_group/vars/main.yml b/tests/integration/targets/ec2_placement_group/vars/main.yml deleted file mode 100644 index ed97d539c09..00000000000 --- a/tests/integration/targets/ec2_placement_group/vars/main.yml +++ /dev/null @@ -1 +0,0 @@ ----