From 53887dbbd8b77f6d64fc710465cea871cccd01a5 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Thu, 17 Oct 2024 10:27:31 -0400 Subject: [PATCH 1/3] Remove modules --- .../20240613_ec2_placement_group_tags.yml | 2 - plugins/modules/ec2_placement_group.py | 254 -------- plugins/modules/ec2_placement_group_info.py | 138 ----- .../targets/ec2_placement_group/aliases | 3 - .../ec2_placement_group/defaults/main.yml | 1 - .../targets/ec2_placement_group/meta/main.yml | 1 - .../ec2_placement_group/tasks/env_cleanup.yml | 94 --- .../ec2_placement_group/tasks/env_setup.yml | 64 -- .../ec2_placement_group/tasks/main.yml | 557 ------------------ .../targets/ec2_placement_group/vars/main.yml | 1 - 10 files changed, 1115 deletions(-) delete mode 100644 changelogs/fragments/20240613_ec2_placement_group_tags.yml delete mode 100644 plugins/modules/ec2_placement_group.py delete mode 100644 plugins/modules/ec2_placement_group_info.py delete mode 100644 tests/integration/targets/ec2_placement_group/aliases delete mode 100644 tests/integration/targets/ec2_placement_group/defaults/main.yml delete mode 100644 tests/integration/targets/ec2_placement_group/meta/main.yml delete mode 100644 tests/integration/targets/ec2_placement_group/tasks/env_cleanup.yml delete mode 100644 tests/integration/targets/ec2_placement_group/tasks/env_setup.yml delete mode 100644 tests/integration/targets/ec2_placement_group/tasks/main.yml delete mode 100644 tests/integration/targets/ec2_placement_group/vars/main.yml diff --git a/changelogs/fragments/20240613_ec2_placement_group_tags.yml b/changelogs/fragments/20240613_ec2_placement_group_tags.yml deleted file mode 100644 index 16e197cb254..00000000000 --- a/changelogs/fragments/20240613_ec2_placement_group_tags.yml +++ /dev/null @@ -1,2 +0,0 @@ -minor_changes: - - ec2_placement_group - Added support for creating with ``tags`` (https://github.com/ansible-collections/community.aws/pull/2081). diff --git a/plugins/modules/ec2_placement_group.py b/plugins/modules/ec2_placement_group.py deleted file mode 100644 index b045ea34b25..00000000000 --- a/plugins/modules/ec2_placement_group.py +++ /dev/null @@ -1,254 +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 I(Strategy) is set to C(partition). - - Must be a value between C(1) and C(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: 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 -""" - -try: - import botocore -except ImportError: - pass # caught by AnsibleAWSModule - -from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry -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 - - -@AWSRetry.exponential_backoff() -def search_placement_group(connection, module): - """ - Check if a placement group exists. - """ - name = module.params.get("name") - try: - response = connection.describe_placement_groups(Filters=[{"Name": "group-name", "Values": [name]}]) - except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: - module.fail_json_aws(e, msg=f"Couldn't find placement group named [{name}]") - - if len(response["PlacementGroups"]) != 1: - return None - else: - placement_group = response["PlacementGroups"][0] - return { - "name": placement_group["GroupName"], - "state": placement_group["State"], - "strategy": placement_group["Strategy"], - "tags": boto3_tag_list_to_ansible_dict(placement_group.get("Tags")), - } - - -@AWSRetry.exponential_backoff(catch_extra_error_codes=["InvalidPlacementGroup.Unknown"]) -def get_placement_group_information(connection, name): - """ - Retrieve information about a placement group. - """ - response = connection.describe_placement_groups(GroupNames=[name]) - placement_group = response["PlacementGroups"][0] - return { - "name": placement_group["GroupName"], - "state": placement_group["State"], - "strategy": placement_group["Strategy"], - "tags": boto3_tag_list_to_ansible_dict(placement_group.get("Tags")), - } - - -@AWSRetry.exponential_backoff() -def create_placement_group(connection, module): - 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 - params["DryRun"] = module.check_mode - - try: - connection.create_placement_group(**params) - except is_boto3_error_code("DryRunOperation"): - module.exit_json( - changed=True, - placement_group={ - "name": name, - "state": "DryRun", - "strategy": strategy, - "tags": tags, - }, - ) - except ( - botocore.exceptions.ClientError, - botocore.exceptions.BotoCoreError, - ) as e: # pylint: disable=duplicate-except - module.fail_json_aws(e, msg=f"Couldn't create placement group [{name}]") - - module.exit_json(changed=True, placement_group=get_placement_group_information(connection, name)) - - -@AWSRetry.exponential_backoff() -def delete_placement_group(connection, module): - name = module.params.get("name") - - try: - connection.delete_placement_group(GroupName=name, DryRun=module.check_mode) - except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: - module.fail_json_aws(e, msg=f"Couldn't delete placement group [{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") - - if state == "present": - placement_group = search_placement_group(connection, module) - 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": - placement_group = search_placement_group(connection, module) - 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 74b32558246..00000000000 --- a/plugins/modules/ec2_placement_group_info.py +++ /dev/null @@ -1,138 +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 -""" - -try: - from botocore.exceptions import BotoCoreError - from botocore.exceptions import ClientError -except ImportError: - pass # caught by AnsibleAWSModule - -from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict - -from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule - - -def get_placement_groups_details(connection, module): - names = module.params.get("names") - try: - if len(names) > 0: - response = connection.describe_placement_groups( - Filters=[ - { - "Name": "group-name", - "Values": names, - } - ] - ) - else: - response = connection.describe_placement_groups() - except (BotoCoreError, ClientError) as e: - module.fail_json_aws(e, msg=f"Couldn't find placement groups named [{names}]") - - results = [] - for placement_group in response["PlacementGroups"]: - 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") - - placement_groups = get_placement_groups_details(connection, module) - 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 ce626b69c3d..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 - 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 - ec2_eni_info: - filters: - vpc-id: "{{ testing_vpc.vpc.id }}" - register: enis - -- name: delete all ENIs - 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 - 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 - 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 - 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 - 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 - 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 - 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 d48bae66c83..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 - 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 - 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 - 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 - 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 - 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 - 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 eec1b168ef0..00000000000 --- a/tests/integration/targets/ec2_placement_group/tasks/main.yml +++ /dev/null @@ -1,557 +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 - - - assert: - that: - - pg_1_create_check_mode is changed - - pg_1_create_check_mode.placement_group.name == resource_prefix ~ '-pg1' - - pg_1_create_check_mode.placement_group.state == "DryRun" - - '"ec2:CreatePlacementGroup" in pg_1_create_check_mode.resource_actions' - - - name: Create a placement group 1 - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg1' - state: present - register: pg_1_create - - - set_fact: - placement_group_names: "{{ placement_group_names + [pg_1_create.placement_group.name] }}" - - - 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 - - - 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 - - - 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 - - - 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" - - '"ec2:CreatePlacementGroup" not in pg_1_create_check_mode_idem.resource_actions' - - - 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 - - - assert: - that: - - pg_2_create_check_mode is changed - - pg_2_create_check_mode.placement_group.name == resource_prefix ~ '-pg2' - - pg_2_create_check_mode.placement_group.state == "DryRun" - - '"ec2:CreatePlacementGroup" in pg_2_create_check_mode.resource_actions' - - - 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 - - - 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' - - - 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 - - - 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 - - - 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 - - - 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" - - '"ec2:CreatePlacementGroup" not in pg_2_create_check_mode_idem.resource_actions' - - - 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 - - - assert: - that: - - pg_3_create_check_mode is changed - - pg_3_create_check_mode.placement_group.name == resource_prefix ~ '-pg3' - - pg_3_create_check_mode.placement_group.state == "DryRun" - - '"ec2:CreatePlacementGroup" in pg_3_create_check_mode.resource_actions' - - - 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 - - - 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' - - - 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 - - - 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 - - - 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 - - - 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" - - '"ec2:CreatePlacementGroup" not in pg_3_create_check_mode_idem.resource_actions' - - - 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 - - - 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.state == "DryRun" - - pg_4_create_check_mode.placement_group.tags.foo == "test1" - - pg_4_create_check_mode.placement_group.tags.bar == "test2" - - '"ec2:CreatePlacementGroup" in pg_4_create_check_mode.resource_actions' - - - 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 - - - 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' - - - 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 - - - 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 - - - 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 - - - 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" - - '"ec2:CreatePlacementGroup" not in pg_4_create_check_mode_idem.resource_actions' - - - name: List all placement groups. - community.aws.ec2_placement_group_info: - register: all_ec2_placement_groups - -# Delete Placement Group ========================================== - - # On using check_mode for delete placement group operation - # If operation would have succeeded, the error response is DryRunOperation. - # Otherwise, it is UnauthorizedOperation . - - 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 - - - assert: - that: - - pg_1_delete_check_mode is not changed - - pg_1_delete_check_mode.error.code == 'DryRunOperation' - - '"ec2:DeletePlacementGroup" in pg_1_delete_check_mode.resource_actions' - - - name: Delete a placement group 1 - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg1' - state: absent - register: pg_1_delete - - - 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 - - - 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 - - - assert: - that: - - pg_1_delete_check_mode_idem is not changed - - '"ec2:DeletePlacementGroup" not in pg_1_delete_check_mode_idem.resource_actions' - - - 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 - - - assert: - that: - - pg_2_delete_check_mode is not changed - - pg_2_delete_check_mode.error.code == 'DryRunOperation' - - '"ec2:DeletePlacementGroup" in pg_2_delete_check_mode.resource_actions' - - - name: Delete a placement group 2 - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg2' - state: absent - register: pg_2_delete - - - 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 - - - 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 - - - assert: - that: - - pg_2_delete_check_mode_idem is not changed - - '"ec2:DeletePlacementGroup" not in pg_2_delete_check_mode_idem.resource_actions' - - - 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 - - - assert: - that: - - pg_3_delete_check_mode is not changed - - pg_3_delete_check_mode.error.code == 'DryRunOperation' - - '"ec2:DeletePlacementGroup" in pg_3_delete_check_mode.resource_actions' - - - name: Delete a placement group 3 - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg3' - state: absent - register: pg_3_delete - - - 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 - - - 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 - - - assert: - that: - - pg_3_delete_check_mode_idem is not changed - - '"ec2:DeletePlacementGroup" not in pg_3_delete_check_mode_idem.resource_actions' - - - 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 - - - assert: - that: - - pg_4_delete_check_mode is not changed - - pg_4_delete_check_mode.error.code == 'DryRunOperation' - - '"ec2:DeletePlacementGroup" in pg_4_delete_check_mode.resource_actions' - - - - name: Delete a placement group 4 - community.aws.ec2_placement_group: - name: '{{ resource_prefix }}-pg4' - state: absent - register: pg_4_delete - - - 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 - - - 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 - - - assert: - that: - - pg_4_delete_check_mode_idem is not changed - - '"ec2:DeletePlacementGroup" not in pg_4_delete_check_mode_idem.resource_actions' - - 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 @@ ---- From c5de6b8b3aa6cbafb853cda8fb6b0a79e3e544a3 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Thu, 17 Oct 2024 10:27:34 -0400 Subject: [PATCH 2/3] Update runtime --- meta/runtime.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/meta/runtime.yml b/meta/runtime.yml index ea50b016258..cb99b7e7664 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 @@ -520,6 +518,10 @@ plugin_routing: redirect: amazon.aws.s3_bucket_info sts_assume_role: redirect: amazon.aws.sts_assume_role + 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 \ No newline at end of file From 5d3015f851a2c4b6403b3752550add0bfa95a93a Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Thu, 17 Oct 2024 10:27:34 -0400 Subject: [PATCH 3/3] Add changelog fragment --- changelogs/fragments/migrate_ec2_placement_group.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelogs/fragments/migrate_ec2_placement_group.yml 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``.