Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_fabric_wide_settings.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_fabric_wide_settings
17 short_description: Manage Fabric Wide Settings (infra:SetPol)
18 description:
19 - Manage Fabric Wide Settings on Cisco ACI fabrics.
20 options:
21 disable_remote_ep_learning:
22 description:
23 - Whether to disable remote endpoint learning in VRFs containing external bridged/routed domains.
24 - The APIC defaults to C(false) when unset during creation.
25 type: bool
26 enforce_subnet_check:
27 description:
28 - Whether to disable IP address learning on the outside of subnets configured in a VRF, for all VRFs.
29 - The APIC defaults to C(false) when unset during creation.
30 type: bool
31 enforce_epg_vlan_validation:
32 description:
33 - Whether to perform a validation check that prevents overlapping VLAN pools from being associated to an EPG.
34 - The APIC defaults to C(false) when unset during creation.
35 type: bool
36 enforce_domain_validation:
37 description:
38 - Whether to perform a validation check if a static path is added but no domain is associated to an EPG.
39 - Asking for domain validation is a one time operation. Once enabled, it cannot be disabled.
40 - The APIC defaults to C(false) when unset during creation.
41 type: bool
42 spine_opflex_client_auth:
43 description:
44 - Whether to enforce Opflex client certificate authentication on spine switches for GOLF and Linux.
45 - The APIC defaults to C(true) when unset during creation.
46 type: bool
47 leaf_opflex_client_auth:
48 description:
49 - Whether to enforce Opflex client certificate authentication on leaf switches for GOLF and Linux.
50 - The APIC defaults to C(true) when unset during creation.
51 type: bool
52 spine_ssl_opflex:
53 description:
54 - Whether to enable SSL Opflex transport for spine switches.
55 - The APIC defaults to C(true) when unset during creation.
56 type: bool
57 leaf_ssl_opflex:
58 description:
59 - Whether to enable SSL Opflex transport for leaf switches.
60 - The APIC defaults to C(true) when unset during creation.
61 type: bool
62 opflex_ssl_versions:
63 description:
64 - Which versions of TLS to enable for Opflex.
65 - When setting any of the TLS versions, you must explicitly set the state for all of them.
66 type: list
67 elements: str
68 choices: [ tls_v1.0, tls_v1.1, tls_v1.2 ]
69 reallocate_gipo:
70 description:
71 - Whether to reallocate some non-stretched BD gipos to make room for stretched BDs.
72 - Asking for gipo reallocation is a one time operation. Once enabled, it cannot be disabled.
73 - The APIC defaults to C(false) when unset during creation.
74 type: bool
75 restrict_infra_vlan_traffic:
76 description:
77 - Whether to restrict infra VLAN traffic to only specified network paths. These enabled network paths are defined by infra security entry policies.
78 - The APIC defaults to C(false) when unset during creation.
79 type: bool
80 state:
81 description:
82 - Use C(present) for updating configuration.
83 - Use C(query) for showing current configuration.
84 type: str
85 choices: [ present, query ]
86 default: present
87 extends_documentation_fragment:
88 - cisco.aci.aci
89 - cisco.aci.annotation
90 - cisco.aci.owner
91
92 seealso:
93 - name: APIC Management Information Model reference
94 description: More information about the internal APIC class B(infra:SetPol).
95 link: https://developer.cisco.com/docs/apic-mim-ref/
96 author:
97 - Tim Cragg (@timcragg)
98 - Akini Ross (@akinross)
99 """
100
101 EXAMPLES = r"""
102 - name: Update Fabric Wide Settings
103 cisco.aci.aci_fabric_wide_settings:
104 host: apic
105 username: admin
106 password: SomeSecretPassword
107 disable_remote_ep_learning: true
108 enforce_epg_vlan_validation: true
109 state: present
110 delegate_to: localhost
111
112 - name: Update Opflex SSL versions
113 cisco.aci.aci_fabric_wide_settings:
114 host: apic
115 username: admin
116 password: SomeSecretPassword
117 opflex_ssl_versions: [tls_v1.2]
118 state: present
119 delegate_to: localhost
120
121 - name: Query Fabric Wide Settings
122 cisco.aci.aci_fabric_wide_settings:
123 host: apic
124 username: admin
125 password: SomeSecretPassword
126 state: query
127 delegate_to: localhost
128 register: query_result
129 """
130
131 RETURN = r"""
132 current:
133 description: The existing configuration from the APIC after the module has finished
134 returned: success
135 type: list
136 sample:
137 [
138 {
139 "fvTenant": {
140 "attributes": {
141 "descr": "Production environment",
142 "dn": "uni/tn-production",
143 "name": "production",
144 "nameAlias": "",
145 "ownerKey": "",
146 "ownerTag": ""
147 }
148 }
149 }
150 ]
151 error:
152 description: The error information as returned from the APIC
153 returned: failure
154 type: dict
155 sample:
156 {
157 "code": "122",
158 "text": "unknown managed object class foo"
159 }
160 raw:
161 description: The raw output returned by the APIC REST API (xml or json)
162 returned: parse error
163 type: str
164 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
165 sent:
166 description: The actual/minimal configuration pushed to the APIC
167 returned: info
168 type: list
169 sample:
170 {
171 "fvTenant": {
172 "attributes": {
173 "descr": "Production environment"
174 }
175 }
176 }
177 previous:
178 description: The original configuration from the APIC before the module has started
179 returned: info
180 type: list
181 sample:
182 [
183 {
184 "fvTenant": {
185 "attributes": {
186 "descr": "Production",
187 "dn": "uni/tn-production",
188 "name": "production",
189 "nameAlias": "",
190 "ownerKey": "",
191 "ownerTag": ""
192 }
193 }
194 }
195 ]
196 proposed:
197 description: The assembled configuration from the user-provided parameters
198 returned: info
199 type: dict
200 sample:
201 {
202 "fvTenant": {
203 "attributes": {
204 "descr": "Production environment",
205 "name": "production"
206 }
207 }
208 }
209 filter_string:
210 description: The filter string used for the request
211 returned: failure or debug
212 type: str
213 sample: ?rsp-prop-include=config-only
214 method:
215 description: The HTTP method used for the request to the APIC
216 returned: failure or debug
217 type: str
218 sample: POST
219 response:
220 description: The HTTP response from the APIC
221 returned: failure or debug
222 type: str
223 sample: OK (30 bytes)
224 status:
225 description: The HTTP status from the APIC
226 returned: failure or debug
227 type: int
228 sample: 200
229 url:
230 description: The HTTP url used for the request to the APIC
231 returned: failure or debug
232 type: str
233 sample: https://10.11.12.13/api/mo/uni/tn-production.json
234 """
235
236 from ansible.module_utils.basic import AnsibleModule
237 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
238 from ansible_collections.cisco.aci.plugins.module_utils.constants import OPFLEX_TLS_MAPPING
239
240
241 def main():
242 argument_spec = aci_argument_spec()
243 argument_spec.update(aci_annotation_spec())
244 argument_spec.update(aci_owner_spec())
245 argument_spec.update(
246 disable_remote_ep_learning=dict(type="bool"),
247 enforce_subnet_check=dict(type="bool"),
248 enforce_epg_vlan_validation=dict(type="bool"),
249 enforce_domain_validation=dict(type="bool"),
250 spine_opflex_client_auth=dict(type="bool"),
251 leaf_opflex_client_auth=dict(type="bool"),
252 spine_ssl_opflex=dict(type="bool"),
253 leaf_ssl_opflex=dict(type="bool"),
254 opflex_ssl_versions=dict(type="list", choices=list(OPFLEX_TLS_MAPPING.keys()), elements="str"),
255 reallocate_gipo=dict(type="bool"),
256 restrict_infra_vlan_traffic=dict(type="bool"),
257 state=dict(type="str", default="present", choices=["present", "query"]),
258 )
259
260 module = AnsibleModule(
261 argument_spec=argument_spec,
262 supports_check_mode=True,
263 )
264
265 aci = ACIModule(module)
266
267 disable_remote_ep_learning = aci.boolean(module.params.get("disable_remote_ep_learning"))
268 enforce_subnet_check = aci.boolean(module.params.get("enforce_subnet_check"))
269 enforce_epg_vlan_validation = aci.boolean(module.params.get("enforce_epg_vlan_validation"))
270 enforce_domain_validation = aci.boolean(module.params.get("enforce_domain_validation"))
271 spine_opflex_client_auth = aci.boolean(module.params.get("spine_opflex_client_auth"))
272 leaf_opflex_client_auth = aci.boolean(module.params.get("leaf_opflex_client_auth"))
273 spine_ssl_opflex = aci.boolean(module.params.get("spine_ssl_opflex"))
274 leaf_ssl_opflex = aci.boolean(module.params.get("leaf_ssl_opflex"))
275 opflex_ssl_versions = module.params.get("opflex_ssl_versions")
276 reallocate_gipo = aci.boolean(module.params.get("reallocate_gipo"))
277 restrict_infra_vlan_traffic = aci.boolean(module.params.get("restrict_infra_vlan_traffic"))
278 state = module.params.get("state")
279
280 aci.construct_url(
281 root_class=dict(
282 aci_class="infraSetPol",
283 aci_rn="infra/settings",
284 ),
285 )
286
287 aci.get_existing()
288
289 if state == "present":
290 class_config = dict(
291 unicastXrEpLearnDisable=disable_remote_ep_learning,
292 enforceSubnetCheck=enforce_subnet_check,
293 validateOverlappingVlans=enforce_epg_vlan_validation,
294 domainValidation=enforce_domain_validation,
295 opflexpAuthenticateClients=spine_opflex_client_auth,
296 leafOpflexpAuthenticateClients=leaf_opflex_client_auth,
297 opflexpUseSsl=spine_ssl_opflex,
298 leafOpflexpUseSsl=leaf_ssl_opflex,
299 reallocateGipo=reallocate_gipo,
300 restrictInfraVLANTraffic=restrict_infra_vlan_traffic,
301 )
302 if opflex_ssl_versions is not None:
303 class_config["opflexpSslProtocols"] = ",".join([OPFLEX_TLS_MAPPING.get(tls) for tls in sorted(opflex_ssl_versions)])
304
305 aci.payload(
306 aci_class="infraSetPol",
307 class_config=class_config,
308 )
309
310 aci.get_diff(aci_class="infraSetPol")
311
312 aci.post_config()
313
314 aci.exit_json()
315
316
317 if __name__ == "__main__":
318 main()