Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_system_global_aes_passphrase_encryption.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Tim Cragg (@timcragg) <[email protected]>
5 # Copyright: (c) 2023, Akini Ross (@akinross) <[email protected]>
6 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
7
8 from __future__ import absolute_import, division, print_function
9
10 __metaclass__ = type
11
12 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
13
14 DOCUMENTATION = r"""
15 ---
16 module: aci_system_global_aes_passphrase_encryption
17 short_description: Manage Global AES Passphrase Encryption Settings (pki:ExportEncryptionKey)
18 description:
19 - Manage Global AES Passphrase Encryption Settings on Cisco ACI fabrics.
20 options:
21 passphrase:
22 description:
23 - The AES passphrase to use for configuration export encryption.
24 - This cannot be modified once in place on the APIC. To modify an existing passphrase, you must delete it by sending a request with state C(absent).
25 - The value of the passphrase will not be shown in the results of a C(query).
26 type: str
27 enable:
28 description:
29 - Whether to enable strong encryption.
30 - The APIC defaults to C(false) when unset during creation.
31 - Note that this will be set back to False when deleting an existing passphrase.
32 type: bool
33 state:
34 description:
35 - Use C(present) to create a passphrase or to change the enable setting.
36 - Use C(absent) to delete the existing passphrase.
37 - Use C(query) for showing current configuration.
38 type: str
39 choices: [ absent, present, query ]
40 default: present
41 extends_documentation_fragment:
42 - cisco.aci.aci
43 - cisco.aci.annotation
44 - cisco.aci.owner
45
46 seealso:
47 - name: APIC Management Information Model reference
48 description: More information about the internal APIC class B(pki:ExportEncryptionKey).
49 link: https://developer.cisco.com/docs/apic-mim-ref/
50 author:
51 - Tim Cragg (@timcragg)
52 - Akini Ross (@akinross)
53 """
54
55 EXAMPLES = r"""
56 - name: Enable encryption with a passphrase
57 cisco.aci.aci_system_global_aes_passphrase_encryption:
58 host: apic
59 username: admin
60 password: SomeSecretPassword
61 passphrase: ansible_passphrase
62 enable: 'yes'
63 state: present
64 delegate_to: localhost
65
66 - name: Query passphrase settings
67 cisco.aci.aci_system_global_aes_passphrase_encryption:
68 host: apic
69 username: admin
70 password: SomeSecretPassword
71 state: query
72 delegate_to: localhost
73 register: query_result
74
75 - name: Clear encryption key
76 cisco.aci.aci_system_global_aes_passphrase_encryption:
77 host: apic
78 username: admin
79 password: SomeSecretPassword
80 state: absent
81 delegate_to: localhost
82 """
83
84 RETURN = r"""
85 current:
86 description: The existing configuration from the APIC after the module has finished
87 returned: success
88 type: list
89 sample:
90 [
91 {
92 "fvTenant": {
93 "attributes": {
94 "descr": "Production environment",
95 "dn": "uni/tn-production",
96 "name": "production",
97 "nameAlias": "",
98 "ownerKey": "",
99 "ownerTag": ""
100 }
101 }
102 }
103 ]
104 error:
105 description: The error information as returned from the APIC
106 returned: failure
107 type: dict
108 sample:
109 {
110 "code": "122",
111 "text": "unknown managed object class foo"
112 }
113 raw:
114 description: The raw output returned by the APIC REST API (xml or json)
115 returned: parse error
116 type: str
117 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
118 sent:
119 description: The actual/minimal configuration pushed to the APIC
120 returned: info
121 type: list
122 sample:
123 {
124 "fvTenant": {
125 "attributes": {
126 "descr": "Production environment"
127 }
128 }
129 }
130 previous:
131 description: The original configuration from the APIC before the module has started
132 returned: info
133 type: list
134 sample:
135 [
136 {
137 "fvTenant": {
138 "attributes": {
139 "descr": "Production",
140 "dn": "uni/tn-production",
141 "name": "production",
142 "nameAlias": "",
143 "ownerKey": "",
144 "ownerTag": ""
145 }
146 }
147 }
148 ]
149 proposed:
150 description: The assembled configuration from the user-provided parameters
151 returned: info
152 type: dict
153 sample:
154 {
155 "fvTenant": {
156 "attributes": {
157 "descr": "Production environment",
158 "name": "production"
159 }
160 }
161 }
162 filter_string:
163 description: The filter string used for the request
164 returned: failure or debug
165 type: str
166 sample: ?rsp-prop-include=config-only
167 method:
168 description: The HTTP method used for the request to the APIC
169 returned: failure or debug
170 type: str
171 sample: POST
172 response:
173 description: The HTTP response from the APIC
174 returned: failure or debug
175 type: str
176 sample: OK (30 bytes)
177 status:
178 description: The HTTP status from the APIC
179 returned: failure or debug
180 type: int
181 sample: 200
182 url:
183 description: The HTTP url used for the request to the APIC
184 returned: failure or debug
185 type: str
186 sample: https://10.11.12.13/api/mo/uni/tn-production.json
187 """
188
189 from ansible.module_utils.basic import AnsibleModule
190 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
191
192
193 def main():
194 argument_spec = aci_argument_spec()
195 argument_spec.update(aci_annotation_spec())
196 argument_spec.update(aci_owner_spec())
197 argument_spec.update(
198 passphrase=dict(type="str", no_log=True),
199 enable=dict(type="bool"),
200 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
201 )
202
203 module = AnsibleModule(
204 argument_spec=argument_spec,
205 supports_check_mode=True,
206 )
207
208 aci = ACIModule(module)
209
210 passphrase = module.params.get("passphrase")
211 enable = aci.boolean(module.params.get("enable"))
212 state = module.params.get("state")
213
214 aci.construct_url(
215 root_class=dict(
216 aci_class="pkiExportEncryptionKey",
217 aci_rn="exportcryptkey",
218 ),
219 )
220
221 aci.get_existing()
222
223 if state in ["present", "absent"]:
224 class_config = dict(passphrase=passphrase, strongEncryptionEnabled=enable) if state == "present" else dict(clearEncryptionKey="yes")
225
226 aci.payload(aci_class="pkiExportEncryptionKey", class_config=class_config)
227
228 aci.get_diff(aci_class="pkiExportEncryptionKey")
229
230 aci.post_config()
231
232 aci.exit_json()
233
234
235 if __name__ == "__main__":
236 main()