Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_certificate_management_policy_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'community'}
12
13 DOCUMENTATION = r'''
14 ---
15 module: intersight_certificate_management_policy_info
16 short_description: Gather information about Certificate Management Policies in Cisco Intersight
17 description:
18 - Gather information about Certificate Management Policies in L(Cisco Intersight,https://intersight.com).
19 - Information can be filtered by O(organization) and O(name).
20 - If no filters are passed, all Certificate Management Policies will be returned.
21 - Optionally retrieves associated certificates for each policy.
22 extends_documentation_fragment: intersight
23 options:
24 organization:
25 description:
26 - The name of the organization the Certificate Management Policy belongs to.
27 type: str
28 name:
29 description:
30 - The name of the Certificate Management Policy to gather information from.
31 type: str
32 author:
33 - Ron Gershburg (@rgershbu)
34 '''
35
36 EXAMPLES = r'''
37 - name: Fetch a specific Certificate Management Policy by name
38 cisco.intersight.intersight_certificate_management_policy_info:
39 api_private_key: "{{ api_private_key }}"
40 api_key_id: "{{ api_key_id }}"
41 name: "CertMgmt-Policy-01"
42
43 - name: Fetch all Certificate Management Policies in a specific Organization
44 cisco.intersight.intersight_certificate_management_policy_info:
45 api_private_key: "{{ api_private_key }}"
46 api_key_id: "{{ api_key_id }}"
47 organization: "default"
48
49 - name: Fetch all Certificate Management Policies
50 cisco.intersight.intersight_certificate_management_policy_info:
51 api_private_key: "{{ api_private_key }}"
52 api_key_id: "{{ api_key_id }}"
53 '''
54
55 RETURN = r'''
56 api_response:
57 description: The API response output returned by the specified resource.
58 returned: always
59 type: list
60 elements: dict
61 sample: [
62 {
63 "Name": "CertMgmt-Policy-01",
64 "ObjectType": "certificatemanagement.Policy",
65 "Moid": "1234567890abcdef12345678",
66 "Description": "Certificate management policy with Root CA",
67 "Organization": {
68 "Name": "default",
69 "Moid": "abcdef1234567890abcdef12",
70 "ObjectType": "organization.Organization"
71 },
72 "Tags": [
73 {
74 "Key": "Environment",
75 "Value": "Production"
76 }
77 ],
78 "Certificates": [
79 {
80 "Certificate": {
81 "PemCertificate": "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0t..."
82 },
83 "CertificateName": "RootCA-01",
84 "ObjectType": "certificatemanagement.RootCaCertificate",
85 "Enabled": true,
86 "Moid": "cert1234567890abcdef12345"
87 }
88 ]
89 },
90 {
91 "Name": "CertMgmt-Policy-02",
92 "ObjectType": "certificatemanagement.Policy",
93 "Moid": "5678901234abcdef56789012",
94 "Description": "Certificate management policy with IMC certificate",
95 "Organization": {
96 "Name": "default",
97 "Moid": "abcdef1234567890abcdef12",
98 "ObjectType": "organization.Organization"
99 },
100 "Certificates": [
101 {
102 "Certificate": {
103 "PemCertificate": "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0t..."
104 },
105 "ObjectType": "certificatemanagement.Imc",
106 "Enabled": true,
107 "IsPrivatekeySet": true,
108 "Moid": "imccert1234567890abcdef"
109 }
110 ]
111 }
112 ]
113 '''
114
115
116 from ansible.module_utils.basic import AnsibleModule
117 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
118
119
120 def main():
121 argument_spec = intersight_argument_spec.copy()
122 argument_spec.update(
123 organization=dict(type='str'),
124 name=dict(type='str')
125 )
126
127 module = AnsibleModule(
128 argument_spec,
129 supports_check_mode=True,
130 )
131
132 intersight = IntersightModule(module)
133 intersight.result['api_response'] = {}
134 intersight.result['trace_id'] = ''
135
136 # Resource path used to fetch info
137 resource_path = '/certificatemanagement/Policies'
138
139 # Build query parameters
140 query_params = intersight.set_query_params()
141
142 # Get policies (certificates are included in the policy response)
143 intersight.get_resource(
144 resource_path=resource_path,
145 query_params=query_params,
146 return_list=True
147 )
148
149 module.exit_json(**intersight.result)
150
151
152 if __name__ == '__main__':
153 main()