Debian Codegraph @

ansible_collections/amazon/aws/plugins/modules/backup_selection_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: Ansible Project
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7
8 DOCUMENTATION = r"""
9 ---
10 module: backup_selection_info
11 version_added: 6.0.0
12 short_description: Describe AWS Backup Selections
13 description:
14 - Lists info about Backup Selection configuration for a given Backup Plan.
15 author:
16 - Gomathi Selvi Srinivasan (@GomathiselviS)
17 - Kristof Imre Szabo (@krisek)
18 - Alina Buzachis (@alinabuzachis)
19 options:
20 backup_plan_name:
21 description:
22 - Uniquely identifies the backup plan to be associated with the selection of resources.
23 required: true
24 type: str
25 aliases:
26 - plan_name
27 backup_selection_names:
28 description:
29 - Uniquely identifies the backup plan the selections should be listed for.
30 type: list
31 elements: str
32 aliases:
33 - selection_names
34 extends_documentation_fragment:
35 - amazon.aws.common.modules
36 - amazon.aws.region.modules
37 - amazon.aws.boto3
38 """
39
40 EXAMPLES = r"""
41 # Note: These examples do not set authentication details, see the AWS Guide for details.
42 - name: Gather information about all backup selections
43 amazon.aws.backup_selection_info:
44 backup_plan_name: "{{ backup_plan_name }}"
45
46 - name: Gather information about a particular backup selection
47 amazon.aws.backup_selection_info:
48 backup_plan_name: "{{ backup_plan_name }}"
49 backup_selection_names:
50 - "{{ backup_selection_name }}"
51 """
52
53 RETURN = r"""
54 backup_selections:
55 description: List of backup selection objects. Each element consists of a dict with all the information related to that backup selection.
56 type: list
57 elements: dict
58 returned: always
59 contains:
60 backup_plan_id:
61 description: Backup plan id.
62 returned: always
63 type: str
64 sample: "1111f877-1ecf-4d79-9718-a861cd09df3b"
65 creation_date:
66 description: Backup plan creation date.
67 returned: always
68 type: str
69 sample: "2023-01-24T10:08:03.193000+01:00"
70 iam_role_arn:
71 description: IAM role arn.
72 returned: always
73 type: str
74 sample: "arn:aws:iam::111122223333:role/system-backup"
75 selection_id:
76 description: Backup selection id.
77 returned: always
78 type: str
79 sample: "1111c217-5d71-4a55-8728-5fc4e63d437b"
80 selection_name:
81 description: Backup selection name.
82 returned: always
83 type: str
84 sample: elastic
85 conditions:
86 description: List of conditions (expressed as a dict) that are defined to assign resources to the backup plan using tags.
87 returned: always
88 type: dict
89 sample: {}
90 list_of_tags:
91 description: Conditions defined to assign resources to the backup plans using tags.
92 returned: always
93 type: list
94 elements: dict
95 sample: []
96 not_resources:
97 description: List of Amazon Resource Names (ARNs) that are excluded from the backup plan.
98 returned: always
99 type: list
100 sample: []
101 resources:
102 description: List of Amazon Resource Names (ARNs) that are assigned to the backup plan.
103 returned: always
104 type: list
105 sample: []
106 """
107
108
109 try:
110 import botocore
111 except ImportError:
112 pass # Handled by AnsibleAWSModule
113
114 from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
115
116 from ansible_collections.amazon.aws.plugins.module_utils.backup import get_selection_details
117 from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
118 from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
119
120
121 def main():
122 argument_spec = dict(
123 backup_plan_name=dict(type="str", required=True, aliases=["plan_name"]),
124 backup_selection_names=dict(type="list", elements="str", aliases=["selection_names"]),
125 )
126 result = {}
127
128 module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)
129
130 try:
131 client = module.client("backup", retry_decorator=AWSRetry.jittered_backoff())
132 except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
133 module.fail_json_aws(e, msg="Failed to connect to AWS")
134
135 result["backup_selections"] = get_selection_details(
136 module, client, module.params.get("backup_plan_name"), module.params.get("backup_selection_names")
137 )
138 module.exit_json(**camel_dict_to_snake_dict(result))
139
140
141 if __name__ == "__main__":
142 main()