Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2024, Akini Ross (@akinross) <[email protected]>
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8
9 __metaclass__ = type
10
11 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_fabric_management_access_https_cipher
16 short_description: Manage Fabric Management Access HTTPS SSL Cipher Configuration (comm:Cipher)
17 description:
18 - Manage Fabric Management Access HTTPS SSL Cipher Configuration on Cisco ACI fabrics.
19 options:
20 fabric_management_access_policy_name:
21 description:
22 - The name of the Fabric Management Access policy.
23 type: str
24 aliases: [ name ]
25 id:
26 description:
27 - The ID of the SSL Cipher Configuration.
28 type: str
29 cipher_state:
30 description:
31 - The state of the SSL Cipher Configuration.
32 type: str
33 choices: [ enabled, disabled ]
34 name_alias:
35 description:
36 - The name alias of the Fabric Management Access HTTPS SSL Cipher Configuration.
37 - This relates to the nameAlias property in ACI.
38 type: str
39 state:
40 description:
41 - Use C(present) for updating configuration.
42 - Use C(query) for showing current configuration.
43 type: str
44 choices: [ absent, present, query ]
45 default: present
46 extends_documentation_fragment:
47 - cisco.aci.aci
48 - cisco.aci.annotation
49 - cisco.aci.owner
50
51 notes:
52 - The C(fabric_management_access_policy_name) must exist before using this module in your playbook.
53 The M(cisco.aci.aci_fabric_management_access) module can be used for this.
54 seealso:
55 - name: APIC Management Information Model reference
56 description: More information about the internal APIC class B(comm:Cipher).
57 link: https://developer.cisco.com/docs/apic-mim-ref/
58 author:
59 - Akini Ross (@akinross)
60 """
61
62 EXAMPLES = r"""
63 - name: Create a Fabric Management Access HTTPS SSL Cipher
64 cisco.aci.aci_fabric_management_access_https_cipher:
65 host: apic
66 username: admin
67 password: SomeSecretPassword
68 fabric_management_access_policy_name: fabric_management_access_policy_1
69 id: DHE-RSA-AES128-SHA
70 cipher_state: enabled
71 state: present
72 delegate_to: localhost
73
74 - name: Query a Fabric Management Access HTTPS SSL Cipher
75 cisco.aci.aci_fabric_management_access_https_cipher:
76 host: apic
77 username: admin
78 password: SomeSecretPassword
79 fabric_management_access_policy_name: fabric_management_access_policy_1
80 id: DHE-RSA-AES128-SHA
81 state: query
82 delegate_to: localhost
83 register: query_result
84
85 - name: Query all Fabric Management Access policies
86 cisco.aci.aci_fabric_management_access_https_cipher:
87 host: apic
88 username: admin
89 password: SomeSecretPassword
90 state: query
91 delegate_to: localhost
92 register: query_result
93
94 - name: Delete a Fabric Management Access HTTPS SSL Cipher
95 cisco.aci.aci_fabric_management_access_https_cipher:
96 host: apic
97 username: admin
98 password: SomeSecretPassword
99 fabric_management_access_policy_name: fabric_management_access_policy_1
100 id: DHE-RSA-AES128-SHA
101 state: absent
102 delegate_to: localhost
103 """
104
105 RETURN = r"""
106 current:
107 description: The existing configuration from the APIC after the module has finished
108 returned: success
109 type: list
110 sample:
111 [
112 {
113 "fvTenant": {
114 "attributes": {
115 "descr": "Production environment",
116 "dn": "uni/tn-production",
117 "name": "production",
118 "nameAlias": "",
119 "ownerKey": "",
120 "ownerTag": ""
121 }
122 }
123 }
124 ]
125 error:
126 description: The error information as returned from the APIC
127 returned: failure
128 type: dict
129 sample:
130 {
131 "code": "122",
132 "text": "unknown managed object class foo"
133 }
134 raw:
135 description: The raw output returned by the APIC REST API (xml or json)
136 returned: parse error
137 type: str
138 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
139 sent:
140 description: The actual/minimal configuration pushed to the APIC
141 returned: info
142 type: list
143 sample:
144 {
145 "fvTenant": {
146 "attributes": {
147 "descr": "Production environment"
148 }
149 }
150 }
151 previous:
152 description: The original configuration from the APIC before the module has started
153 returned: info
154 type: list
155 sample:
156 [
157 {
158 "fvTenant": {
159 "attributes": {
160 "descr": "Production",
161 "dn": "uni/tn-production",
162 "name": "production",
163 "nameAlias": "",
164 "ownerKey": "",
165 "ownerTag": ""
166 }
167 }
168 }
169 ]
170 proposed:
171 description: The assembled configuration from the user-provided parameters
172 returned: info
173 type: dict
174 sample:
175 {
176 "fvTenant": {
177 "attributes": {
178 "descr": "Production environment",
179 "name": "production"
180 }
181 }
182 }
183 filter_string:
184 description: The filter string used for the request
185 returned: failure or debug
186 type: str
187 sample: ?rsp-prop-include=config-only
188 method:
189 description: The HTTP method used for the request to the APIC
190 returned: failure or debug
191 type: str
192 sample: POST
193 response:
194 description: The HTTP response from the APIC
195 returned: failure or debug
196 type: str
197 sample: OK (30 bytes)
198 status:
199 description: The HTTP status from the APIC
200 returned: failure or debug
201 type: int
202 sample: 200
203 url:
204 description: The HTTP url used for the request to the APIC
205 returned: failure or debug
206 type: str
207 sample: https://10.11.12.13/api/mo/uni/tn-production.json
208 """
209
210 from ansible.module_utils.basic import AnsibleModule
211 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
212
213
214 def main():
215 argument_spec = aci_argument_spec()
216 argument_spec.update(aci_annotation_spec())
217 argument_spec.update(aci_owner_spec())
218 argument_spec.update(
219 fabric_management_access_policy_name=dict(type="str", aliases=["name"]), # Not required for querying all objects
220 id=dict(type="str"),
221 cipher_state=dict(type="str", choices=["enabled", "disabled"]),
222 name_alias=dict(type="str"),
223 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
224 )
225
226 module = AnsibleModule(
227 argument_spec=argument_spec,
228 supports_check_mode=True,
229 required_if=[
230 ["state", "present", ["fabric_management_access_policy_name", "id", "cipher_state"]],
231 ["state", "absent", ["fabric_management_access_policy_name", "id"]],
232 ],
233 )
234
235 aci = ACIModule(module)
236 aci_class = "commCipher"
237
238 fabric_management_access_policy_name = module.params.get("fabric_management_access_policy_name")
239 id_value = module.params.get("id")
240 cipher_state = module.params.get("cipher_state")
241 name_alias = module.params.get("name_alias")
242 state = module.params.get("state")
243
244 aci.construct_url(
245 root_class=dict(
246 aci_class=aci_class,
247 aci_rn="fabric/comm-{0}".format(fabric_management_access_policy_name),
248 module_object=fabric_management_access_policy_name,
249 target_filter={"name": fabric_management_access_policy_name},
250 ),
251 subclass_1=dict(
252 aci_class=aci_class,
253 aci_rn="https/cph-{0}".format(id_value),
254 module_object=id_value,
255 target_filter={"id": id_value},
256 ),
257 )
258
259 aci.get_existing()
260
261 if state == "present":
262 aci.payload(
263 aci_class=aci_class,
264 class_config=dict(
265 id=id_value,
266 state=cipher_state,
267 nameAlias=name_alias,
268 ),
269 )
270
271 aci.get_diff(aci_class=aci_class)
272
273 aci.post_config()
274
275 elif state == "absent":
276 aci.delete_config()
277
278 aci.exit_json()
279
280
281 if __name__ == "__main__":
282 main()