Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2022, Tim Cragg (@timcragg)
5 # Copyright: (c) 2024, Akini Ross (@akinross)
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": "community"}
13
14 DOCUMENTATION = r"""
15 ---
16 module: aci_dns_profile
17 short_description: Manage DNS Profile objects (dns:Profile)
18 description:
19 - Manage DNS Profile configuration on Cisco ACI fabrics.
20 options:
21 dns_profile:
22 description:
23 - Name of the DNS profile.
24 type: str
25 aliases: [ name, profile_name ]
26 management_epg:
27 description:
28 - Name of the management EPG.
29 - Specify C("") to remove the management EPG configuration.
30 type: str
31 aliases: [ epg ]
32 management_epg_type:
33 description:
34 - The type of the management EPG.
35 type: str
36 choices: [ inband, ooband ]
37 aliases: [ type ]
38 default: ooband
39 state:
40 description:
41 - Use C(present) or C(absent) for adding or removing.
42 - Use C(query) for listing an object or multiple objects.
43 type: str
44 choices: [ absent, present, query ]
45 default: present
46 extends_documentation_fragment:
47 - cisco.aci.aci
48 - cisco.aci.annotation
49
50 seealso:
51 - name: APIC Management Information Model reference
52 description: More information about the internal APIC class B(dns:Profile).
53 link: https://developer.cisco.com/docs/apic-mim-ref/
54 author:
55 - Tim Cragg (@timcragg)
56 - Akini Ross (@akinross)
57 """
58
59 EXAMPLES = r"""
60 - name: Add a new DNS profile
61 cisco.aci.aci_dns_profile:
62 host: apic
63 username: admin
64 password: SomeSecretPassword
65 dns_profile: my_dns_prof
66 state: present
67 delegate_to: localhost
68
69 - name: Add a new DNS profile with a inband management EPG
70 cisco.aci.aci_dns_profile:
71 host: apic
72 username: admin
73 password: SomeSecretPassword
74 dns_profile: my_dns_prof
75 management_epg: ansible_mgmt_epg_inband
76 management_epg_type: inband
77 state: present
78 delegate_to: localhost
79
80 - name: Add a new DNS profile with a out-of-band management EPG
81 cisco.aci.aci_dns_profile:
82 host: apic
83 username: admin
84 password: SomeSecretPassword
85 dns_profile: my_dns_prof
86 management_epg: ansible_mgmt_epg_ooband
87 state: present
88 delegate_to: localhost
89
90 - name: Remove a management EPG from a DNS profile
91 cisco.aci.aci_dns_profile:
92 host: apic
93 username: admin
94 password: SomeSecretPassword
95 dns_profile: my_dns_prof
96 management_epg: ""
97 state: present
98 delegate_to: localhost
99
100 - name: Query a DNS profile
101 cisco.aci.aci_dns_profile:
102 host: apic
103 username: admin
104 password: SomeSecretPassword
105 dns_profile: my_dns_prof
106 state: query
107 delegate_to: localhost
108 register: query_result
109
110 - name: Query all DNS profiles
111 cisco.aci.aci_dns_profile:
112 host: apic
113 username: admin
114 password: SomeSecretPassword
115 state: query
116 delegate_to: localhost
117 register: query_result
118
119 - name: Remove a DNS profile
120 cisco.aci.aci_dns_profile:
121 host: apic
122 username: admin
123 password: SomeSecretPassword
124 dns_profile: my_dns_prof
125 state: absent
126 delegate_to: localhost
127 """
128
129 RETURN = r"""
130 current:
131 description: The existing configuration from the APIC after the module has finished
132 returned: success
133 type: list
134 sample:
135 [
136 {
137 "fvTenant": {
138 "attributes": {
139 "descr": "Production environment",
140 "dn": "uni/tn-production",
141 "name": "production",
142 "nameAlias": "",
143 "ownerKey": "",
144 "ownerTag": ""
145 }
146 }
147 }
148 ]
149 error:
150 description: The error information as returned from the APIC
151 returned: failure
152 type: dict
153 sample:
154 {
155 "code": "122",
156 "text": "unknown managed object class foo"
157 }
158 raw:
159 description: The raw output returned by the APIC REST API (xml or json)
160 returned: parse error
161 type: str
162 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class "/></imdata>'
163 sent:
164 description: The actual/minimal configuration pushed to the APIC
165 returned: info
166 type: list
167 sample:
168 {
169 "fvTenant": {
170 "attributes": {
171 "descr": "Production environment"
172 }
173 }
174 }
175 previous:
176 description: The original configuration from the APIC before the module has started
177 returned: info
178 type: list
179 sample:
180 [
181 {
182 "fvTenant": {
183 "attributes": {
184 "descr": "Production",
185 "dn": "uni/tn-production",
186 "name": "production",
187 "nameAlias": "",
188 "ownerKey": "",
189 "ownerTag": ""
190 }
191 }
192 }
193 ]
194 proposed:
195 description: The assembled configuration from the user-provided parameters
196 returned: info
197 type: dict
198 sample:
199 {
200 "fvTenant": {
201 "attributes": {
202 "descr": "Production environment",
203 "name": "production"
204 }
205 }
206 }
207 filter_string:
208 description: The filter string used for the request
209 returned: failure or debug
210 type: str
211 sample: ?rsp-prop-include=config-only
212 method:
213 description: The HTTP method used for the request to the APIC
214 returned: failure or debug
215 type: str
216 sample: POST
217 response:
218 description: The HTTP response from the APIC
219 returned: failure or debug
220 type: str
221 sample: OK (30 bytes)
222 status:
223 description: The HTTP status from the APIC
224 returned: failure or debug
225 type: int
226 sample: 200
227 url:
228 description: The HTTP url used for the request to the APIC
229 returned: failure or debug
230 type: str
231 sample: https://10.11.12.13/api/mo/uni/tn-production.json
232 """
233
234 from ansible.module_utils.basic import AnsibleModule
235 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
236 from ansible_collections.cisco.aci.plugins.module_utils.constants import MANAGEMENT_EPG_TYPE
237
238
239 def main():
240 argument_spec = aci_argument_spec()
241 argument_spec.update(aci_annotation_spec())
242 argument_spec.update(
243 dns_profile=dict(type="str", aliases=["name", "profile_name"]),
244 management_epg=dict(type="str", aliases=["epg"]),
245 management_epg_type=dict(type="str", default="ooband", choices=["inband", "ooband"], aliases=["type"]),
246 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
247 )
248
249 module = AnsibleModule(
250 argument_spec=argument_spec,
251 supports_check_mode=True,
252 required_if=[
253 ["state", "absent", ["dns_profile"]],
254 ["state", "present", ["dns_profile"]],
255 ],
256 )
257
258 dns_profile = module.params.get("dns_profile")
259 management_epg = module.params.get("management_epg")
260 management_epg_type = MANAGEMENT_EPG_TYPE.get(module.params.get("management_epg_type"))
261 state = module.params.get("state")
262 child_classes = ["dnsProv", "dnsDomain", "dnsRsProfileToEpg"]
263
264 aci = ACIModule(module)
265 aci.construct_url(
266 root_class=dict(
267 aci_class="dnsProfile",
268 aci_rn="fabric/dnsp-{0}".format(dns_profile),
269 module_object=dns_profile,
270 target_filter={"name": dns_profile},
271 ),
272 child_classes=child_classes,
273 )
274
275 aci.get_existing()
276
277 if state == "present":
278
279 child_configs = []
280 if management_epg is not None:
281 if management_epg == "":
282 child_configs.append(
283 dict(
284 dnsRsProfileToEpg=dict(
285 attributes=dict(
286 tDn="",
287 status="deleted",
288 )
289 )
290 )
291 )
292 else:
293 child_configs.append(
294 dict(
295 dnsRsProfileToEpg=dict(
296 attributes=dict(
297 tDn="uni/tn-mgmt/mgmtp-default/{0}-{1}".format(management_epg_type, management_epg),
298 )
299 )
300 )
301 )
302
303 aci.payload(
304 aci_class="dnsProfile",
305 class_config=dict(name=dns_profile),
306 child_configs=child_configs,
307 )
308
309 aci.get_diff(aci_class="dnsProfile")
310
311 aci.post_config()
312
313 elif state == "absent":
314 aci.delete_config()
315
316 aci.exit_json()
317
318
319 if __name__ == "__main__":
320 main()