Debian Codegraph @

ansible_collections/community/dns/docs/docsite/rst/hosttech_guide.rst

raw
1 ..
2 Copyright (c) Ansible Project
3 GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 SPDX-License-Identifier: GPL-3.0-or-later
5
6 .. _ansible_collections.community.dns.docsite.hosttech_guide:
7
8 HostTech DNS Guide
9 ==================
10
11 .. contents:: Contents
12 :local:
13 :depth: 2
14
15 The :anscollection:`community.dns collection <community.dns>` offers several modules for working with the `HostTech DNS service <https://www.hosttech.ch/>`_.
16 The modules support both the old `WSDL-based API <https://ns1.hosttech.eu/public/api?wsdl>`_ and the new `JSON REST based API <https://api.ns1.hosttech.eu/api/documentation/>`_.
17
18 The collection provides six modules for working with HostTech DNS:
19
20 - :ansplugin:`community.dns.hosttech_dns_record#module`: create/update/delete single DNS records
21 - :ansplugin:`community.dns.hosttech_dns_record_info#module`: retrieve information on DNS records
22 - :ansplugin:`community.dns.hosttech_dns_record_set#module`: create/update/delete DNS record sets
23 - :ansplugin:`community.dns.hosttech_dns_record_set_info#module`: retrieve information on DNS record sets
24 - :ansplugin:`community.dns.hosttech_dns_record_sets#module`: bulk synchronize DNS record sets
25 - :ansplugin:`community.dns.hosttech_dns_zone_info#module`: retrieve zone information
26
27 It also provides an inventory plugin:
28
29 - :ansplugin:`community.dns.hosttech_dns_records#inventory`: create inventory from DNS records
30
31 To find out which record types are supported and how to use them, look at :ref:`ansible_collections.community.dns.docsite.hosttech_guide.records`.
32
33 Authentication, Requirements and APIs
34 -------------------------------------
35
36 HostTech currently has two APIs for working with DNS records: the old WSDL-based API, and the new JSON-based REST API. We recommend using the new JSON REST API if possible.
37
38 JSON REST API
39 ~~~~~~~~~~~~~
40
41 To use the JSON REST API, you need to create a API token. You can manage API tokens in the "DNS Editor" in the "API" section. You must provide the token to the :ansopt:`hosttech_token` option of the modules:
42
43 .. code-block:: yaml+jinja
44
45 - community.dns.hosttech_dns_record:
46 hosttech_token: '{{ token }}'
47 # ...
48
49 In the examples in this guide, we will leave the authentication options away. Please note that you can set them globally with ``module_defaults`` (see :ref:`module_defaults`).
50
51 WSDL API
52 ~~~~~~~~
53
54 To use the WSDL API, you need to set API credentials. These can be found and changed in the "Servercenter" and there in the "Solutions" section under settings for the "DNS Tool". The username is fixed, but the password can be changed. The credentials must be provided to the :ansopt:`hosttech_username` and :ansopt:`hosttech_password` options of the modules.
55
56 You also need to install the `lxml Python module <https://pypi.org/project/lxml/>`_ to work with the WSDL API. This can be done before using the modules:
57
58 .. code-block:: yaml+jinja
59
60 - name: Make sure lxml is installed
61 pip:
62 name: lxml
63
64 - community.dns.hosttech_dns_record:
65 hosttech_username: '{{ username }}'
66 hosttech_password: '{{ password }}'
67 # ...
68
69 In the examples in this guide, we will leave the authentication options away. Please note that you can set them globally with ``module_defaults`` (see :ref:`module_defaults`).
70
71 Using the ``community.dns.hosttech`` module defaults group
72 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73
74 To avoid having to specify common parameters for all Hosttech DNS modules in every task, you can use the ``community.dns.hosttech`` module defaults group:
75
76 .. code-block:: yaml+jinja
77
78 ---
79 - name: Hosttech DNS
80 hosts: localhost
81 gather_facts: false
82 module_defaults:
83 group/community.dns.hosttech:
84 hosttech_username: '{{ username }}'
85 hosttech_password: '{{ password }}'
86 tasks:
87 - name: Query zone information
88 community.dns.hosttech_dns_zone_info:
89 zone_name: example.com
90 register: result
91
92 - name: Set A records for www.example.com
93 community.dns.hosttech_dns_record_set:
94 state: present
95 zone_name: example.com
96 type: A
97 prefix: www
98 value:
99 - 192.168.0.1
100
101 Here all two tasks will use the options set for the module defaults group.
102
103 Working with DNS zones
104 ----------------------
105
106 The :ansplugin:`community.dns.hosttech_dns_zone_info module <community.dns.hosttech_dns_zone_info#module>` allows to query information on a zone. The zone can be identified both by its name and by its ID (which is an integer):
107
108 .. code-block:: yaml+jinja
109
110 - name: Query zone information by name
111 community.dns.hosttech_dns_zone_info:
112 zone_name: example.com
113 register: result
114
115 - name: Query zone information by ID
116 community.dns.hosttech_dns_zone_info:
117 zone_id: 42
118 register: result
119
120 The module returns both the zone name and zone ID, so this module can be used to convert from zone ID to zone name and vice versa:
121
122 .. code-block:: yaml+jinja
123
124 - ansible.builtin.debug:
125 msg: |
126 The zone ID: {{ result.zone_id }}
127 The zone name: {{ result.zone_name }}
128
129 Working with DNS records
130 ------------------------
131
132 .. note::
133
134 By default, TXT record values returned and accepted by the modules and plugins in this collection are unquoted. This means that you do not have to add double quotes (``"``), and escape double quotes (as ``\"``) and backslashes (as ``\\``). All modules and plugins which work with DNS records support the :ansopt:`community.dns.hosttech_dns_record_set#module:txt_transformation` option which allows to configure this behavior.
135
136 Querying DNS records and record sets
137 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138
139 The :ansplugin:`community.dns.hosttech_dns_record_set_info module <community.dns.hosttech_dns_record_set_info#module>` allows to query DNS record sets from the API. It can be used to query a single record set:
140
141 .. code-block:: yaml+jinja
142
143 - name: Query single record
144 community.dns.hosttech_dns_record_set_info:
145 zone_name: example.com
146 type: A # IPv4 addresses
147 what: single_record # default value
148 # Either specify a record name:
149 record: www.example.com
150 # Or a record prefix ('' is the zone itself):
151 prefix: www
152 register: result
153
154 - name: Show IPv4 addresses if record exists
155 ansible.builtin.debug:
156 msg: >
157 IPv4s are {{ result.set.value | join(', ') }},
158 TTL is {{ result.set.ttl }}
159 when: result.set is truthy
160
161 - name: Show that record is not set
162 ansible.builtin.debug:
163 msg: There is no A record for www.example.com
164 when: result.set is falsy
165
166 In all examples in this section, you can replace :ansopt:`community.dns.hosttech_dns_record_set_info#module:zone_name=example.com` by :ansopt:`community.dns.hosttech_dns_record_set_info#module:zone_id=42` with the zone's integer ID.
167
168 You can also query a list of all record sets for a record name or prefix:
169
170 .. code-block:: yaml+jinja
171
172 - name: Query all records for www.example.com
173 community.dns.hosttech_dns_record_set_info:
174 zone_name: example.com
175 what: all_types_for_record
176 # Either specify a record name:
177 record: www.example.com
178 # Or a record prefix ('' is the zone itself):
179 prefix: www
180 register: result
181
182 - name: Show all records for www.example.com
183 ansible.builtin.debug:
184 msg: >
185 {{ item.type }} record with TTL {{ item.ttl }} has
186 values {{ item.value | join(', ') }}
187 loop: result.sets
188
189 Finally you can query all record sets for a zone:
190
191 .. code-block:: yaml+jinja
192
193 - name: Query all records for a zone
194 community.dns.hosttech_dns_record_set_info:
195 zone_name: example.com
196 what: all_records
197 register: result
198
199 - name: Show all records for the example.com zone
200 ansible.builtin.debug:
201 msg: >
202 {{ item.type }} record for {{ item.record }} with
203 TTL {{ item.ttl }} has values {{ item.value | join(', ') }}
204 loop: result.sets
205
206 If you are interested in individual DNS records, and not record sets, you should use the :ansplugin:`community.dns.hosttech_dns_record_info module <community.dns.hosttech_dns_record_info#module>`. It supports the same limiting options as the :ansplugin:`community.dns.hosttech_dns_record_set_info module <community.dns.hosttech_dns_record_set_info#module>`.
207
208 Creating and updating DNS single records
209 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
210
211 If you do not want to add/remove values, but replace values, you will be interested in modifying a **record set** and not a single record. This is in particular important when working with ``CNAME`` and ``SOA`` records.
212
213 The :ansplugin:`community.dns.hosttech_dns_record module <community.dns.hosttech_dns_record#module>` allows to set, update and remove single DNS records. Setting and updating can be done as follows. Records will be matched by record name and type, and the TTL value will be updated if necessary:
214
215 .. code-block:: yaml+jinja
216
217 - name: Add an A record with value 1.1.1.1 for www.example.com, resp. make sure the TTL is 300
218 community.dns.hosttech_dns_record:
219 state: present
220 zone_name: example.com
221 type: A # IPv4 addresses
222 # Either specify a record name:
223 record: www.example.com
224 # Or a record prefix ('' is the zone itself):
225 prefix: www
226 value: 1.1.1.1
227 ttl: 300
228
229 To delete records, simply use :ansopt:`community.dns.hosttech_dns_record#module:state=absent`. Records will be matched by record name and type, and the TTL will be ignored:
230
231 .. code-block:: yaml+jinja
232
233 - name: Remove A values for www.example.com
234 community.dns.hosttech_dns_record:
235 state: absent
236 zone_name: example.com
237 type: A # IPv4 addresses
238 record: www.example.com
239 value: 1.1.1.1
240
241 Records of the same type for the same record name with other values are ignored.
242
243 Creating and updating DNS record sets
244 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
245
246 The :ansplugin:`community.dns.hosttech_dns_record_set module <community.dns.hosttech_dns_record_set#module>` allows to set, update and remove DNS record sets. Setting and updating can be done as follows:
247
248 .. code-block:: yaml+jinja
249
250 - name: Make sure record is set to the given value
251 community.dns.hosttech_dns_record_set:
252 state: present
253 zone_name: example.com
254 type: A # IPv4 addresses
255 # Either specify a record name:
256 record: www.example.com
257 # Or a record prefix ('' is the zone itself):
258 prefix: www
259 value:
260 - 1.1.1.1
261 - 8.8.8.8
262
263 If you want to assert that a record has a certain value, set :ansopt:`community.dns.hosttech_dns_record_set#module:on_existing=keep`. Using :ansval:`keep_and_warn` instead will emit a warning if this happens, and :ansval:`keep_and_fail` will make the module fail.
264
265 To delete values, you can either overwrite the values with value :ansval:`[]`, or use :ansopt:`community.dns.hosttech_dns_record_set#module:state=absent`:
266
267 .. code-block:: yaml+jinja
268
269 - name: Remove A values for www.example.com
270 community.dns.hosttech_dns_record_set:
271 state: present
272 zone_name: example.com
273 type: A # IPv4 addresses
274 record: www.example.com
275 value: []
276
277 - name: Remove TXT values for www.example.com
278 community.dns.hosttech_dns_record_set:
279 zone_name: example.com
280 type: TXT
281 prefix: www
282 state: absent
283
284 - name: Remove specific AAAA values for www.example.com
285 community.dns.hosttech_dns_record_set:
286 zone_name: example.com
287 type: AAAA # IPv6 addresses
288 prefix: www
289 state: absent
290 on_existing: keep_and_fail
291 ttl: 300
292 value:
293 - '::1'
294
295 In the third example, :ansopt:`community.dns.hosttech_dns_record_set#module:on_existing=keep_and_fail` is present and an explicit value and TTL are given. This makes the module remove the current value only if there's a AAAA record for ``www.example.com`` whose current value is ``::1`` and whose TTL is 300. If another value is set, the module will not make any change, but fail. This can be useful to not accidentally remove values you do not want to change. To issue a warning instead of failing, use :ansopt:`community.dns.hosttech_dns_record_set#module:on_existing=keep_and_warn`, and to simply not do a change without any indication of this situation, use :ansopt:`community.dns.hosttech_dns_record_set#module:on_existing=keep`.
296
297 Bulk synchronization of DNS record sets
298 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
299
300 If you want to set/update multiple records at once, or even make sure that the precise set of records you are providing are present and nothing else, you can use the :ansplugin:`community.dns.hosttech_dns_record_sets module <community.dns.hosttech_dns_record_sets#module>`.
301
302 The following example shows up to set/update multiple records at once:
303
304 .. code-block:: yaml+jinja
305
306 - name: Make sure that multiple records are present
307 community.dns.hosttech_dns_record_sets:
308 zone_name: example.com
309 record_sets:
310 - prefix: www
311 type: A
312 value:
313 - 1.1.1.1
314 - 8.8.8.8
315 - prefix: www
316 type: AAAA
317 value:
318 - '::1'
319
320 The next example shows how to make sure that only the given records are available and all other records are deleted. Note that for the :ansopt:`community.dns.hosttech_dns_record_sets#module:record_sets[].type=NS` record we used :ansopt:`community.dns.hosttech_dns_record_sets#module:record_sets[].ignore=true`, which allows us to skip the value. It tells the module that it should not touch the ``NS`` record for ``example.com``.
321
322 .. code-block:: yaml+jinja
323
324 - name: Make sure that multiple records are present
325 community.dns.hosttech_dns_record_sets:
326 zone_name: example.com
327 prune: true
328 record_sets:
329 - prefix: www
330 type: A
331 value:
332 - 1.1.1.1
333 - 8.8.8.8
334 - prefix: www
335 type: AAAA
336 value:
337 - '::1'
338 - prefix: ''
339 type: NS
340 ignore: true
341
342 .. _ansible_collections.community.dns.docsite.hosttech_guide.records:
343
344 Supported DNS records
345 ---------------------
346
347 Here you can find a list of supported DNS records together with their syntax for the :ansopt:`value` field:
348
349 - **A** records: IPv4 address.
350
351 Simply provide the IPv4 address as :ansopt:`value`, such as ``127.0.0.1``.
352 - **AAAA** records: IPv6 address.
353
354 Simply provide the IPv6 address as :ansopt:`value`, such as ``3fff::1:2``.
355 - **CAA** records: Certification Authority Authorization
356
357 The record's :ansopt:`value` is of the form ``<flags> <tag> <value>``,
358 where ``<flags>`` is an unsigned integer between 0 and 255;
359 ``<tag>`` is a ASCII string such as ``issue``, ``issuewild``, or ``iodef``;
360 and ``<value>`` is the value enclosed in double quotes.
361 An example entry is ``0 issue "letsencrypt.org"``.
362 The exact syntax is explained in L(Section 4.1.1 of RFC 8659, https://datatracker.ietf.org/doc/html/rfc8659#name-syntax).
363 - **CNAME** records: Canonical Name.
364 - **MX** records: Mail Exchange.
365
366 The record's :ansopt:`value` is of the form ``<priority> <hostname>``,
367 where ``<priority>`` is an unsigned integer and ``<hostname>`` a DNS hostname.
368 - **NS** records: Name Server record.
369
370 The record's :ansopt:`value` is the list of DNS names of the authoritative nameservers for this zone.
371 - **PTR** records: Pointer to a canonical name.
372
373 The record's :ansopt:`value` is of the form ``<origin> <ptr-name>``.
374 - **SPF** records: Sender Policy Framework.
375
376 This kind of DNS record is deprecated, TXT records should be used instead for SPF policies.
377 - **SRV** records: Service locator.
378
379 The record's :ansopt:`value` is of the form ``<priority> <weight> <port> <target>``.
380 - **TXT** records: Text record.
381
382 The value is simply a free form text. Its use depends on its context.