Debian Codegraph @

ansible_collections/community/aws/plugins/modules/cloudformation_exports_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 DOCUMENTATION = r"""
8 module: cloudformation_exports_info
9 short_description: Read a value from CloudFormation Exports
10 version_added: 1.0.0
11 description:
12 - Module retrieves a value from CloudFormation Exports
13 author:
14 - "Michael Moyle (@mmoyle)"
15 extends_documentation_fragment:
16 - amazon.aws.common.modules
17 - amazon.aws.region.modules
18 - amazon.aws.boto3
19 """
20
21 EXAMPLES = r"""
22 # Note: These examples do not set authentication details, see the AWS Guide for details.
23 - name: Get Exports
24 community.aws.cloudformation_exports_info: {}
25 register: cf_exports
26 - ansible.builtin.debug:
27 msg: "{{ cf_exports }}"
28 """
29
30 RETURN = r"""
31 export_items:
32 description: A dictionary of Exports items names and values.
33 returned: Always
34 type: dict
35 """
36
37 try:
38 from botocore.exceptions import BotoCoreError
39 from botocore.exceptions import ClientError
40 except ImportError:
41 pass # handled by AnsibleAWSModule
42
43 from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
44
45 from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule
46
47
48 @AWSRetry.exponential_backoff()
49 def list_exports(cloudformation_client):
50 """Get Exports Names and Values and return in dictionary"""
51 list_exports_paginator = cloudformation_client.get_paginator("list_exports")
52 exports = list_exports_paginator.paginate().build_full_result()["Exports"]
53 export_items = dict()
54
55 for item in exports:
56 export_items[item["Name"]] = item["Value"]
57
58 return export_items
59
60
61 def main():
62 argument_spec = dict()
63 result = dict(changed=False, original_message="")
64
65 module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)
66 cloudformation_client = module.client("cloudformation")
67
68 try:
69 result["export_items"] = list_exports(cloudformation_client)
70
71 except (ClientError, BotoCoreError) as e:
72 module.fail_json_aws(e)
73
74 result.update()
75 module.exit_json(**result)
76
77
78 if __name__ == "__main__":
79 main()