Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2022, Sabari Jaganathan (@sajagana) <[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_aaa_custom_privilege
16 short_description: Manage AAA RBAC Custom Privileges (aaa:RbacClassPriv)
17 description:
18 - Manage AAA Custom Privileges with RBAC Rules on Cisco ACI fabrics.
19 options:
20 name:
21 description:
22 - Name of the object class for which you are configuring access.
23 type: str
24 aliases: [ custom_privilege_name ]
25 description:
26 description:
27 - Description of the AAA custom privilege.
28 type: str
29 aliases: [ descr ]
30 write_privilege:
31 description:
32 - Name of the custom privilege that will include write access to objects of the class.
33 type: str
34 aliases: [ write_priv, w_priv ]
35 choices: [
36 custom-privilege-1,
37 custom-privilege-2,
38 custom-privilege-3,
39 custom-privilege-4,
40 custom-privilege-5,
41 custom-privilege-6,
42 custom-privilege-7,
43 custom-privilege-8,
44 custom-privilege-9,
45 custom-privilege-10,
46 custom-privilege-11,
47 custom-privilege-12,
48 custom-privilege-13,
49 custom-privilege-14,
50 custom-privilege-15,
51 custom-privilege-16,
52 custom-privilege-17,
53 custom-privilege-18,
54 custom-privilege-19,
55 custom-privilege-20,
56 custom-privilege-21,
57 custom-privilege-22
58 ]
59 read_privilege:
60 description:
61 - Name of the custom privilege that will include read access to objects of the class.
62 type: str
63 aliases: [ read_priv, r_priv ]
64 choices: [
65 custom-privilege-1,
66 custom-privilege-2,
67 custom-privilege-3,
68 custom-privilege-4,
69 custom-privilege-5,
70 custom-privilege-6,
71 custom-privilege-7,
72 custom-privilege-8,
73 custom-privilege-9,
74 custom-privilege-10,
75 custom-privilege-11,
76 custom-privilege-12,
77 custom-privilege-13,
78 custom-privilege-14,
79 custom-privilege-15,
80 custom-privilege-16,
81 custom-privilege-17,
82 custom-privilege-18,
83 custom-privilege-19,
84 custom-privilege-20,
85 custom-privilege-21,
86 custom-privilege-22
87 ]
88 state:
89 description:
90 - Use C(present) or C(absent) for adding or removing.
91 - Use C(query) for listing an object or multiple objects.
92 type: str
93 choices: [ absent, present, query ]
94 default: present
95 name_alias:
96 description:
97 - The alias for the current object. This relates to the nameAlias field in ACI.
98 type: str
99 extends_documentation_fragment:
100 - cisco.aci.aci
101
102 seealso:
103 - module: cisco.aci.aci_aaa_domain
104 - name: APIC Management Information Model reference
105 description: More information about the internal APIC class B(aaa:Domain).
106 link: https://developer.cisco.com/docs/apic-mim-ref/
107 author:
108 - Sabari Jaganathan (@sajagana)
109 """
110
111 EXAMPLES = r"""
112 - name: Add a custom privilege
113 cisco.aci.aci_aaa_custom_privilege:
114 host: apic
115 username: admin
116 password: SomeSecretPassword
117 name: fabricPod
118 write_privilege: custom-privilege-1
119 read_privilege: custom-privilege-1
120 state: present
121 delegate_to: localhost
122
123 - name: Add list of custom privileges
124 cisco.aci.aci_aaa_custom_privilege:
125 host: apic
126 username: admin
127 password: SomeSecretPassword
128 name: "{{ item.name }}"
129 write_privilege: "{{ item.write_privilege }}"
130 read_privilege: "{{ item.read_privilege | default('') }}"
131 state: present
132 with_items:
133 - name: fvTenant
134 write_privilege: custom-privilege-2
135 read_privilege: custom-privilege-2
136 - name: aaaUser
137 write_privilege: custom-privilege-3
138 delegate_to: localhost
139
140 - name: Query a custom privilege with name
141 cisco.aci.aci_aaa_custom_privilege:
142 host: apic
143 username: admin
144 password: SomeSecretPassword
145 name: fabricPod
146 state: query
147 delegate_to: localhost
148
149 - name: Query all custom privileges
150 cisco.aci.aci_aaa_custom_privilege:
151 host: apic
152 username: admin
153 password: SomeSecretPassword
154 state: query
155 delegate_to: localhost
156
157 - name: Remove a custom privilege
158 cisco.aci.aci_aaa_custom_privilege:
159 host: apic
160 username: admin
161 password: SomeSecretPassword
162 name: fabricPod
163 state: absent
164 delegate_to: localhost
165 """
166
167 RETURN = r"""
168 current:
169 description: The existing configuration from the APIC after the module has finished
170 returned: success
171 type: list
172 sample:
173 [
174 {
175 "fvTenant": {
176 "attributes": {
177 "descr": "Production environment",
178 "dn": "uni/tn-production",
179 "name": "production",
180 "nameAlias": "",
181 "ownerKey": "",
182 "ownerTag": ""
183 }
184 }
185 }
186 ]
187 error:
188 description: The error information as returned from the APIC
189 returned: failure
190 type: dict
191 sample:
192 {
193 "code": "122",
194 "text": "unknown managed object class foo"
195 }
196 raw:
197 description: The raw output returned by the APIC REST API (xml or json)
198 returned: parse error
199 type: str
200 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
201 sent:
202 description: The actual/minimal configuration pushed to the APIC
203 returned: info
204 type: list
205 sample:
206 {
207 "fvTenant": {
208 "attributes": {
209 "descr": "Production environment"
210 }
211 }
212 }
213 previous:
214 description: The original configuration from the APIC before the module has started
215 returned: info
216 type: list
217 sample:
218 [
219 {
220 "fvTenant": {
221 "attributes": {
222 "descr": "Production",
223 "dn": "uni/tn-production",
224 "name": "production",
225 "nameAlias": "",
226 "ownerKey": "",
227 "ownerTag": ""
228 }
229 }
230 }
231 ]
232 proposed:
233 description: The assembled configuration from the user-provided parameters
234 returned: info
235 type: dict
236 sample:
237 {
238 "fvTenant": {
239 "attributes": {
240 "descr": "Production environment",
241 "name": "production"
242 }
243 }
244 }
245 filter_string:
246 description: The filter string used for the request
247 returned: failure or debug
248 type: str
249 sample: '?rsp-prop-include=config-only'
250 method:
251 description: The HTTP method used for the request to the APIC
252 returned: failure or debug
253 type: str
254 sample: POST
255 response:
256 description: The HTTP response from the APIC
257 returned: failure or debug
258 type: str
259 sample: OK (30 bytes)
260 status:
261 description: The HTTP status from the APIC
262 returned: failure or debug
263 type: int
264 sample: 200
265 url:
266 description: The HTTP url used for the request to the APIC
267 returned: failure or debug
268 type: str
269 sample: https://10.11.12.13/api/mo/uni/tn-production.json
270 """
271
272 from ansible.module_utils.basic import AnsibleModule
273 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec
274
275 CUSTOM_PRIVILEGES = [
276 "custom-privilege-1",
277 "custom-privilege-2",
278 "custom-privilege-3",
279 "custom-privilege-4",
280 "custom-privilege-5",
281 "custom-privilege-6",
282 "custom-privilege-7",
283 "custom-privilege-8",
284 "custom-privilege-9",
285 "custom-privilege-10",
286 "custom-privilege-11",
287 "custom-privilege-12",
288 "custom-privilege-13",
289 "custom-privilege-14",
290 "custom-privilege-15",
291 "custom-privilege-16",
292 "custom-privilege-17",
293 "custom-privilege-18",
294 "custom-privilege-19",
295 "custom-privilege-20",
296 "custom-privilege-21",
297 "custom-privilege-22",
298 ]
299
300
301 def main():
302 argument_spec = aci_argument_spec()
303 argument_spec.update(
304 name=dict(type="str", aliases=["custom_privilege_name"]),
305 description=dict(type="str", aliases=["descr"]),
306 write_privilege=dict(
307 type="str",
308 aliases=["write_priv", "w_priv"],
309 choices=CUSTOM_PRIVILEGES,
310 ),
311 read_privilege=dict(
312 type="str",
313 aliases=["read_priv", "r_priv"],
314 choices=CUSTOM_PRIVILEGES,
315 ),
316 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
317 name_alias=dict(type="str"),
318 )
319
320 module = AnsibleModule(
321 argument_spec=argument_spec,
322 supports_check_mode=True,
323 required_if=[
324 ["state", "absent", ["name"]],
325 ["state", "present", ["name"]],
326 ],
327 )
328
329 aci = ACIModule(module)
330
331 name = module.params.get("name")
332 description = module.params.get("description")
333 w_priv = module.params.get("write_privilege")
334 r_priv = module.params.get("read_privilege")
335 state = module.params.get("state")
336 name_alias = module.params.get("name_alias")
337
338 aci.construct_url(
339 root_class=dict(aci_class="aaaRbacClassPriv", aci_rn="rbacdb/rbacclpriv-{0}".format(name), module_object=name, target_filter=dict(name=name)),
340 )
341 aci.get_existing()
342
343 if state == "present":
344 aci.payload(
345 aci_class="aaaRbacClassPriv",
346 class_config=dict(
347 name=name,
348 descr=description,
349 wPriv=w_priv,
350 rPriv=r_priv,
351 nameAlias=name_alias,
352 ),
353 )
354
355 aci.get_diff(aci_class="aaaRbacClassPriv")
356
357 aci.post_config()
358
359 elif state == "absent":
360 aci.delete_config()
361
362 aci.exit_json()
363
364
365 if __name__ == "__main__":
366 main()