Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2022, Tim Cragg (@timcragg)
5 # Copyright: (c) 2022, Sabari Jaganathan (@sajagana) <[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_aaa_user_domain
17 short_description: Manage AAA user domains (aaa:UserDomain)
18 description:
19 - Manage AAA user domain configuration on Cisco ACI fabrics.
20 options:
21 aaa_user:
22 description:
23 - The name of an existing AAA user
24 type: str
25 aliases: [ user_name ]
26 aaa_user_type:
27 description:
28 - Whether this is a normal user or an appuser.
29 type: str
30 choices: [ appuser, user ]
31 default: user
32 name:
33 description:
34 - The name of the user domain
35 type: str
36 aliases: [ domain_name, user_domain ]
37 name_alias:
38 description:
39 - The alias for the current object. This relates to the nameAlias field in ACI.
40 type: str
41 state:
42 description:
43 - Use C(present) or C(absent) for adding or removing.
44 - Use C(query) for listing an object or multiple objects.
45 type: str
46 choices: [ absent, present, query ]
47 default: present
48 extends_documentation_fragment:
49 - cisco.aci.aci
50 - cisco.aci.annotation
51 - cisco.aci.owner
52
53 notes:
54 - The C(aaa_user) must exist before using this module in your playbook.
55 The M(cisco.aci.aci_aaa_user) modules can be used for this.
56 seealso:
57 - name: APIC Management Information Model reference
58 description: More information about the internal APIC class B(aaaUserDomain).
59 link: https://developer.cisco.com/docs/apic-mim-ref/
60 author:
61 - Tim Cragg (@timcragg)
62 - Sabari Jaganathan (@sajagana)
63 """
64
65 EXAMPLES = r"""
66 - name: Add a security domain to a aaa_user
67 cisco.aci.aci_aaa_user_domain:
68 host: apic
69 username: admin
70 password: SomeSecretPassword
71 aaa_user: my_user
72 name: my_domain
73 state: present
74 delegate_to: localhost
75
76 - name: Remove a security domain from a aaa_user
77 cisco.aci.aci_aaa_user_domain:
78 host: apic
79 username: admin
80 password: SomeSecretPassword
81 aaa_user: my_user
82 name: my_domain
83 state: absent
84 delegate_to: localhost
85
86 - name: Add list of security domains to a aaa_user
87 cisco.aci.aci_aaa_user_domain:
88 host: apic
89 username: admin
90 password: SomeSecretPassword
91 aaa_user: my_user
92 name: "{{ item.name }}"
93 state: present
94 with_items:
95 - name: common
96 - name: all
97 - name: mgmt
98 delegate_to: localhost
99
100 - name: Query a security domain from a aaa_user
101 cisco.aci.aci_aaa_user_domain:
102 host: apic
103 username: admin
104 password: SomeSecretPassword
105 aaa_user: my_user
106 name: my_domain
107 state: query
108 delegate_to: localhost
109 register: query_result
110
111 - name: Query all security domains of a aaa_user
112 cisco.aci.aci_aaa_user_domain:
113 host: apic
114 username: admin
115 password: SomeSecretPassword
116 aaa_user: my_user
117 state: query
118 delegate_to: localhost
119 register: query_results
120
121 - name: Query all security domains to user associations
122 cisco.aci.aci_aaa_user_domain:
123 host: apic
124 username: admin
125 password: SomeSecretPassword
126 state: query
127 delegate_to: localhost
128 register: query_all_domains
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
239 ACI_MAPPING = dict(
240 appuser=dict(
241 aci_class="aaaAppUser",
242 aci_mo="userext/appuser-",
243 ),
244 user=dict(
245 aci_class="aaaUser",
246 aci_mo="userext/user-",
247 ),
248 )
249
250
251 def main():
252 argument_spec = aci_argument_spec()
253 argument_spec.update(aci_annotation_spec())
254 argument_spec.update(aci_owner_spec())
255 argument_spec.update(
256 aaa_user=dict(type="str", aliases=["user_name"]),
257 name=dict(type="str", aliases=["domain_name", "user_domain"]),
258 aaa_user_type=dict(type="str", default="user", choices=["appuser", "user"]),
259 name_alias=dict(type="str"),
260 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
261 )
262
263 module = AnsibleModule(
264 argument_spec=argument_spec,
265 supports_check_mode=True,
266 required_if=[
267 ["state", "absent", ["aaa_user", "name"]],
268 ["state", "present", ["aaa_user", "name"]],
269 ],
270 )
271
272 aaa_user = module.params.get("aaa_user")
273 name = module.params.get("name")
274 aaa_user_type = module.params.get("aaa_user_type")
275 name_alias = module.params.get("name_alias")
276 state = module.params.get("state")
277
278 child_classes = ["aaaUserRole"]
279
280 aci = ACIModule(module)
281 aci.construct_url(
282 root_class=dict(
283 aci_class=ACI_MAPPING.get(aaa_user_type).get("aci_class"),
284 aci_rn="{0}{1}".format(ACI_MAPPING.get(aaa_user_type).get("aci_mo"), aaa_user),
285 module_object=aaa_user,
286 target_filter={"name": aaa_user},
287 ),
288 subclass_1=dict(
289 aci_class="aaaUserDomain",
290 aci_rn="userdomain-{0}".format(name),
291 module_object=name,
292 target_filter={"name": name},
293 ),
294 child_classes=child_classes,
295 )
296 aci.get_existing()
297
298 if state == "present":
299 aci.payload(
300 aci_class="aaaUserDomain",
301 class_config=dict(
302 name=name,
303 nameAlias=name_alias,
304 ),
305 )
306
307 aci.get_diff(aci_class="aaaUserDomain")
308
309 aci.post_config()
310
311 elif state == "absent":
312 aci.delete_config()
313
314 aci.exit_json()
315
316
317 if __name__ == "__main__":
318 main()