Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2022, Tim Cragg (@timcragg)
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": "community"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_dns_provider
16 short_description: Manage DNS Provider objects (dns:Prov)
17 description:
18 - Manage DNS Provider configuration on Cisco ACI fabrics.
19 options:
20 dns_profile:
21 description:
22 - Name of the DNS profile.
23 type: str
24 aliases: [ profile_name ]
25 required: true
26 address:
27 description:
28 - address of the DNS server
29 type: str
30 aliases: [ addr, ip_address ]
31 preferred:
32 description:
33 - Whether this is the preferred DNS server
34 type: bool
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 extends_documentation_fragment:
43 - cisco.aci.aci
44 - cisco.aci.annotation
45
46 notes:
47 - The C(dns_profile) must exist before using this module in your playbook.
48 The M(cisco.aci.aci_dns_profile) modules can be used for this.
49
50 seealso:
51 - name: APIC Management Information Model reference
52 description: More information about the internal APIC class B(dnsProv).
53 link: https://developer.cisco.com/docs/apic-mim-ref/
54 author:
55 - Tim Cragg (@timcragg)
56 """
57
58 EXAMPLES = r"""
59 - name: Add a new DNS provider
60 cisco.aci.aci_dns_provider:
61 host: apic
62 username: admin
63 password: SomeSecretPassword
64 dns_profile: my_dns_prof
65 address: 10.20.30.40
66 state: present
67 delegate_to: localhost
68
69 - name: Remove a DNS provider
70 cisco.aci.aci_dns_profile:
71 host: apic
72 username: admin
73 password: SomeSecretPassword
74 dns_profile: my_dns_prof
75 address: 10.20.30.40
76 state: absent
77 delegate_to: localhost
78
79 - name: Query a DNS provider
80 cisco.aci.aci_dns_profile:
81 host: apic
82 username: admin
83 password: SomeSecretPassword
84 dns_profile: my_dns_prof
85 address: 10.20.30.40
86 state: query
87 delegate_to: localhost
88 register: query_result
89
90 - name: Query all DNS providers within a DNS profile
91 cisco.aci.aci_dns_profile:
92 host: apic
93 username: admin
94 password: SomeSecretPassword
95 state: query
96 delegate_to: localhost
97 register: query_result
98 """
99
100 RETURN = r"""
101 current:
102 description: The existing configuration from the APIC after the module has finished
103 returned: success
104 type: list
105 sample:
106 [
107 {
108 "fvTenant": {
109 "attributes": {
110 "descr": "Production environment",
111 "dn": "uni/tn-production",
112 "name": "production",
113 "nameAlias": "",
114 "ownerKey": "",
115 "ownerTag": ""
116 }
117 }
118 }
119 ]
120 error:
121 description: The error information as returned from the APIC
122 returned: failure
123 type: dict
124 sample:
125 {
126 "code": "122",
127 "text": "unknown managed object class foo"
128 }
129 raw:
130 description: The raw output returned by the APIC REST API (xml or json)
131 returned: parse error
132 type: str
133 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class "/></imdata>'
134 sent:
135 description: The actual/minimal configuration pushed to the APIC
136 returned: info
137 type: list
138 sample:
139 {
140 "fvTenant": {
141 "attributes": {
142 "descr": "Production environment"
143 }
144 }
145 }
146 previous:
147 description: The original configuration from the APIC before the module has started
148 returned: info
149 type: list
150 sample:
151 [
152 {
153 "fvTenant": {
154 "attributes": {
155 "descr": "Production",
156 "dn": "uni/tn-production",
157 "name": "production",
158 "nameAlias": "",
159 "ownerKey": "",
160 "ownerTag": ""
161 }
162 }
163 }
164 ]
165 proposed:
166 description: The assembled configuration from the user-provided parameters
167 returned: info
168 type: dict
169 sample:
170 {
171 "fvTenant": {
172 "attributes": {
173 "descr": "Production environment",
174 "name": "production"
175 }
176 }
177 }
178 filter_string:
179 description: The filter string used for the request
180 returned: failure or debug
181 type: str
182 sample: ?rsp-prop-include=config-only
183 method:
184 description: The HTTP method used for the request to the APIC
185 returned: failure or debug
186 type: str
187 sample: POST
188 response:
189 description: The HTTP response from the APIC
190 returned: failure or debug
191 type: str
192 sample: OK (30 bytes)
193 status:
194 description: The HTTP status from the APIC
195 returned: failure or debug
196 type: int
197 sample: 200
198 url:
199 description: The HTTP url used for the request to the APIC
200 returned: failure or debug
201 type: str
202 sample: https://10.11.12.13/api/mo/uni/tn-production.json
203 """
204
205 from ansible.module_utils.basic import AnsibleModule
206 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
207
208
209 def main():
210 argument_spec = aci_argument_spec()
211 argument_spec.update(aci_annotation_spec())
212 argument_spec.update(
213 dns_profile=dict(type="str", aliases=["profile_name"], required=True),
214 address=dict(type="str", aliases=["addr", "ip_address"]),
215 preferred=dict(type="bool"),
216 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
217 )
218
219 module = AnsibleModule(
220 argument_spec=argument_spec,
221 supports_check_mode=True,
222 required_if=[
223 ["state", "absent", ["address"]],
224 ["state", "present", ["address"]],
225 ],
226 )
227
228 aci = ACIModule(module)
229
230 dns_profile = module.params.get("dns_profile")
231 address = module.params.get("address")
232 preferred = aci.boolean(module.params.get("preferred"))
233 state = module.params.get("state")
234
235 aci.construct_url(
236 root_class=dict(
237 aci_class="dnsProfile",
238 aci_rn="fabric/dnsp-{0}".format(dns_profile),
239 module_object=dns_profile,
240 target_filter={"name": dns_profile},
241 ),
242 subclass_1=dict(aci_class="dnsProv", aci_rn="prov-{0}".format(address), module_object=address, target_filter={"address": address}),
243 )
244
245 aci.get_existing()
246
247 if state == "present":
248 aci.payload(
249 aci_class="dnsProv",
250 class_config=dict(addr=address, preferred=preferred),
251 )
252
253 aci.get_diff(aci_class="dnsProv")
254
255 aci.post_config()
256
257 elif state == "absent":
258 aci.delete_config()
259
260 aci.exit_json()
261
262
263 if __name__ == "__main__":
264 main()