From 9fb1a17eaebc99674756f6a0c41e9a849f959f11 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 4 Jun 2024 09:57:42 -0700 Subject: [PATCH] backup_plan_info: bugfix to enable getting info of all backup plans (#2083) backup_plan_info: bugfix to enable getting info of all backup plans SUMMARY Fix being unable to fetch info of all backup plans. With backup_plan_names being a required parameter, the functionality to get all plans info was not working - name: Get info of all backup plans amazon.aws.backup_plan_info: register: plan_info_result gave ********** fatal: [localhost]: FAILED! => {"changed": false, "msg": "missing required arguments: backup_plan_names"} ISSUE TYPE Bugfix Pull Request COMPONENT NAME backup_plan_info ADDITIONAL INFORMATION Reviewed-by: GomathiselviS Reviewed-by: Alina Buzachis Reviewed-by: Mandar Kulkarni Reviewed-by: Mark Chappell --- CHANGELOG.rst | 15 +++++++++ changelogs/changelog.yaml | 16 ++++++++++ ...lan_info-bugfix-get-info-for-all-plans.yml | 3 ++ plugins/modules/backup_plan_info.py | 23 ++++++++++---- .../targets/backup_plan/tasks/main.yml | 31 ++++++++++++++++++- 5 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/2083-backup_plan_info-bugfix-get-info-for-all-plans.yml diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f867fc9e4e5..7a4fa628a7d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,21 @@ amazon.aws Release Notes .. contents:: Topics +v8.0.1 +====== + +Release Summary +--------------- + +This release includes some bug fixes for the `s3_object`, `ec2_instance` and `backup_plan_info` modules. + +Bugfixes +-------- + +- backup_plan_info - Bugfix to enable getting info of all backup plans (https://github.com/ansible-collections/amazon.aws/pull/2083). +- ec2_instance - do not ignore IPv6 addresses when a single network interface is specified (https://github.com/ansible-collections/amazon.aws/pull/1979). +- s3_object - fixed issue which was causing ``MemoryError`` exceptions when downloading large files (https://github.com/ansible-collections/amazon.aws/issues/2107). + v8.0.0 ====== diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 546b1fe229f..c02fa995c38 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -3026,3 +3026,19 @@ releases: - sanity-boto3.yml - sanity-simple.yml release_date: '2024-05-16' + 8.0.1: + changes: + bugfixes: + - backup_plan_info - Bugfix to enable getting info of all backup plans (https://github.com/ansible-collections/amazon.aws/pull/2083). + - ec2_instance - do not ignore IPv6 addresses when a single network interface + is specified (https://github.com/ansible-collections/amazon.aws/pull/1979). + - s3_object - fixed issue which was causing ``MemoryError`` exceptions when + downloading large files (https://github.com/ansible-collections/amazon.aws/issues/2107). + release_summary: This release includes some bug fixes for the `s3_object`, `ec2_instance` + and `backup_plan_info` modules. + fragments: + - 1979-do-not-ignore-ipv6-addresses.yaml + - 2083-backup_plan_info-bugfix-get-info-for-all-plans.yml + - 2107-s3_download.yml + - release_summary.yml + release_date: '2024-06-05' diff --git a/changelogs/fragments/2083-backup_plan_info-bugfix-get-info-for-all-plans.yml b/changelogs/fragments/2083-backup_plan_info-bugfix-get-info-for-all-plans.yml new file mode 100644 index 00000000000..96bedc378bc --- /dev/null +++ b/changelogs/fragments/2083-backup_plan_info-bugfix-get-info-for-all-plans.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - backup_plan_info - Bugfix to enable getting info of all backup plans (https://github.com/ansible-collections/amazon.aws/pull/2083). diff --git a/plugins/modules/backup_plan_info.py b/plugins/modules/backup_plan_info.py index 8de7809022e..1761d2af68a 100644 --- a/plugins/modules/backup_plan_info.py +++ b/plugins/modules/backup_plan_info.py @@ -20,7 +20,6 @@ backup_plan_names: type: list elements: str - required: true description: - Specifies a list of plan names. extends_documentation_fragment: @@ -31,10 +30,11 @@ EXAMPLES = r""" # Note: These examples do not set authentication details, see the AWS Guide for details. -# Gather information about all backup plans -- amazon.aws.backup_plan_info -# Gather information about a particular backup plan -- amazon.aws.backup_plan_info: +- name: Gather information about all backup plans + amazon.aws.backup_plan_info: + +- name: Gather information about a particular backup plan + amazon.aws.backup_plan_info: backup plan_names: - elastic """ @@ -110,10 +110,21 @@ from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry +def get_all_backup_plans_info(client): + paginator = client.get_paginator("list_backup_plans") + return paginator.paginate().build_full_result() + + def get_backup_plan_detail(client, module): backup_plan_list = [] backup_plan_names = module.params.get("backup_plan_names") + if backup_plan_names is None: + backup_plan_names = [] + backup_plan_list_info = get_all_backup_plans_info(client)["BackupPlansList"] + for backup_plan in backup_plan_list_info: + backup_plan_names.append(backup_plan["BackupPlanName"]) + for name in backup_plan_names: backup_plan_list.extend(get_plan_details(module, client, name)) @@ -122,7 +133,7 @@ def get_backup_plan_detail(client, module): def main(): argument_spec = dict( - backup_plan_names=dict(type="list", elements="str", required=True), + backup_plan_names=dict(type="list", elements="str"), ) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) diff --git a/tests/integration/targets/backup_plan/tasks/main.yml b/tests/integration/targets/backup_plan/tasks/main.yml index ee8f62ec9a5..79e6e147953 100644 --- a/tests/integration/targets/backup_plan/tasks/main.yml +++ b/tests/integration/targets/backup_plan/tasks/main.yml @@ -344,12 +344,41 @@ - backup_plan_create_result.exists is true - backup_plan_create_result.changed is false + - name: Create another backup plan + amazon.aws.backup_plan: + backup_plan_name: "{{ backup_plan_name }}-1" + rules: + - rule_name: daily + target_backup_vault_name: "{{ backup_vault_name }}" + tags: + Environment: Test + register: backup_plan_create_result_1 + + - name: Verify backup plan create result + ansible.builtin.assert: + that: + - backup_plan_create_result_1.exists is true + - backup_plan_create_result_1.changed is true + + - name: Get info of all install plans + amazon.aws.backup_plan_info: + register: backup_plan_info_result + + - name: Assert that info of all backup plans is fetched + ansible.builtin.assert: + that: + - backup_plan_info_result is not failed + - backup_plan_info_result.backup_plans | length > 1 + always: - name: Delete AWS Backup plan created during this test amazon.aws.backup_plan: - backup_plan_name: "{{ backup_plan_name }}" + backup_plan_name: "{{ item }}" state: absent ignore_errors: true + with_items: + - "{{ backup_plan_name }}" + - "{{ backup_plan_name }}-1" - name: Delete AWS Backup vault created during this test amazon.aws.backup_vault: