Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_aaa_domain.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_domain
16 short_description: Manage AAA domains (aaa:Domain)
17 description:
18 - Manage AAA domains on Cisco ACI fabrics.
19 options:
20 name:
21 description:
22 - The name of the aaa domain.
23 type: str
24 aliases: [ aaa_domain ]
25 description:
26 description:
27 - Description of the aaa domain.
28 type: str
29 aliases: [ descr ]
30 restricted_rbac_domain:
31 description:
32 - C(True) to enable Restricted RBAC Domain on the aaa security domain.
33 type: bool
34 choices: [ false, true ]
35 state:
36 description:
37 - Use C(present) or C(absent) for adding or removing.
38 - Use C(query) for listing an object or multiple objects.
39 type: str
40 choices: [ absent, present, query ]
41 default: present
42 name_alias:
43 description:
44 - The alias for the current object. This relates to the nameAlias field in ACI.
45 type: str
46 extends_documentation_fragment:
47 - cisco.aci.aci
48
49 seealso:
50 - module: cisco.aci.aci_aaa_role
51 - name: Manage AAA roles (aaa:Role)
52 description: More information about the AAA roles class B(aaa:Role).
53 link: https://developer.cisco.com/docs/apic-mim-ref/
54 author:
55 - Sabari Jaganathan (@sajagana)
56 """
57
58 EXAMPLES = r"""
59 - name: Add an aaa security domain
60 cisco.aci.aci_aaa_domain:
61 host: apic
62 username: admin
63 password: SomeSecretPassword
64 name: anstest_security_domain
65 description: "Anstest Sec Domain Descr"
66 state: present
67 delegate_to: localhost
68
69 - name: Add list of aaa security domain
70 cisco.aci.aci_aaa_domain:
71 host: apic
72 username: admin
73 password: SomeSecretPassword
74 name: "{{ item.name }}"
75 description: "{{ item.description }}"
76 state: present
77 with_items:
78 - name: anstest1
79 description: "Anstest Sec Domain Descr 1"
80 - name: anstest2
81 description: "Anstest Sec Domain Descr 2"
82 delegate_to: localhost
83
84 - name: Query an aaa security domain with name
85 cisco.aci.aci_aaa_domain:
86 host: apic
87 username: admin
88 password: SomeSecretPassword
89 name: anstest_security_domain
90 state: query
91 delegate_to: localhost
92
93 - name: Query all aaa security domains
94 cisco.aci.aci_aaa_domain:
95 host: apic
96 username: admin
97 password: SomeSecretPassword
98 state: query
99 delegate_to: localhost
100
101 - name: Remove an aaa security domain
102 cisco.aci.aci_aaa_domain:
103 host: apic
104 username: admin
105 password: SomeSecretPassword
106 name: anstest_security_domain
107 state: absent
108 delegate_to: localhost
109 """
110
111 RETURN = r"""
112 current:
113 description: The existing configuration from the APIC after the module has finished
114 returned: success
115 type: list
116 sample:
117 [
118 {
119 "fvTenant": {
120 "attributes": {
121 "descr": "Production environment",
122 "dn": "uni/tn-production",
123 "name": "production",
124 "nameAlias": "",
125 "ownerKey": "",
126 "ownerTag": ""
127 }
128 }
129 }
130 ]
131 error:
132 description: The error information as returned from the APIC
133 returned: failure
134 type: dict
135 sample:
136 {
137 "code": "122",
138 "text": "unknown managed object class foo"
139 }
140 raw:
141 description: The raw output returned by the APIC REST API (xml or json)
142 returned: parse error
143 type: str
144 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
145 sent:
146 description: The actual/minimal configuration pushed to the APIC
147 returned: info
148 type: list
149 sample:
150 {
151 "fvTenant": {
152 "attributes": {
153 "descr": "Production environment"
154 }
155 }
156 }
157 previous:
158 description: The original configuration from the APIC before the module has started
159 returned: info
160 type: list
161 sample:
162 [
163 {
164 "fvTenant": {
165 "attributes": {
166 "descr": "Production",
167 "dn": "uni/tn-production",
168 "name": "production",
169 "nameAlias": "",
170 "ownerKey": "",
171 "ownerTag": ""
172 }
173 }
174 }
175 ]
176 proposed:
177 description: The assembled configuration from the user-provided parameters
178 returned: info
179 type: dict
180 sample:
181 {
182 "fvTenant": {
183 "attributes": {
184 "descr": "Production environment",
185 "name": "production"
186 }
187 }
188 }
189 filter_string:
190 description: The filter string used for the request
191 returned: failure or debug
192 type: str
193 sample: ?rsp-prop-include=config-only
194 method:
195 description: The HTTP method used for the request to the APIC
196 returned: failure or debug
197 type: str
198 sample: POST
199 response:
200 description: The HTTP response from the APIC
201 returned: failure or debug
202 type: str
203 sample: OK (30 bytes)
204 status:
205 description: The HTTP status from the APIC
206 returned: failure or debug
207 type: int
208 sample: 200
209 url:
210 description: The HTTP url used for the request to the APIC
211 returned: failure or debug
212 type: str
213 sample: https://10.11.12.13/api/mo/uni/tn-production.json
214 """
215
216 from ansible.module_utils.basic import AnsibleModule
217 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec
218
219
220 def main():
221 argument_spec = aci_argument_spec()
222 argument_spec.update(
223 name=dict(type="str", aliases=["aaa_domain"]),
224 description=dict(type="str", aliases=["descr"]),
225 restricted_rbac_domain=dict(type="bool", choices=[False, True]),
226 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
227 name_alias=dict(type="str"),
228 )
229
230 module = AnsibleModule(
231 argument_spec=argument_spec,
232 supports_check_mode=True,
233 required_if=[
234 ["state", "absent", ["name"]],
235 ["state", "present", ["name"]],
236 ],
237 )
238
239 name = module.params.get("name")
240 description = module.params.get("description")
241 restricted_rbac_domain = module.params.get("restricted_rbac_domain")
242 state = module.params.get("state")
243 name_alias = module.params.get("name_alias")
244
245 aci = ACIModule(module)
246 aci.construct_url(
247 root_class=dict(
248 aci_class="aaaDomain",
249 aci_rn="userext/domain-{0}".format(name),
250 module_object=name,
251 target_filter=dict(name=name),
252 ),
253 )
254 aci.get_existing()
255
256 if state == "present":
257 restricted_rbac_domain_mapping = {False: "no", True: "yes"}
258 restricted_rbac_domain_state = restricted_rbac_domain_mapping.get(restricted_rbac_domain)
259 aci.payload(
260 aci_class="aaaDomain",
261 class_config=dict(
262 name=name,
263 descr=description,
264 restrictedRbacDomain=restricted_rbac_domain_state,
265 nameAlias=name_alias,
266 ),
267 )
268
269 aci.get_diff(aci_class="aaaDomain")
270
271 aci.post_config()
272
273 elif state == "absent":
274 aci.delete_config()
275
276 aci.exit_json()
277
278
279 if __name__ == "__main__":
280 main()