Debian Codegraph @

ansible_collections/community/dns/plugins/modules/hetzner_dns_record.py

raw
1 #!/usr/bin/python
2 # Copyright (c) 2021 Felix Fontein
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 from __future__ import annotations
7
8 DOCUMENTATION = r"""
9 module: hetzner_dns_record
10
11 short_description: Add or delete a single record in Hetzner DNS service
12
13 version_added: 2.0.0
14
15 description:
16 - Creates and deletes single DNS records in Hetzner DNS service.
17 - If you do not want to add/remove values, but replace values, you will be interested in modifying a B(record set) and not
18 a single record. This is in particular important when working with C(CNAME) and C(SOA) records. Use the M(community.dns.hetzner_dns_record_set)
19 module for working with record sets.
20 extends_documentation_fragment:
21 - community.dns._hetzner
22 - community.dns._hetzner.record_default_ttl
23 - community.dns._hetzner.record_notes
24 - community.dns._hetzner.record_type_choices
25 - community.dns._hetzner.record_type_seealso
26 - community.dns._hetzner.zone_id_type
27 - community.dns._module_record
28 - community.dns._options.record_transformation
29 - community.dns._attributes
30 - community.dns._attributes.actiongroup_hetzner
31
32 attributes:
33 action_group:
34 version_added: 2.4.0
35
36 author:
37 - Markus Bergholz (@markuman) <[email protected]>
38 - Felix Fontein (@felixfontein)
39 """
40
41 EXAMPLES = r"""
42 - name: Add a new.foo.com A record
43 community.dns.hetzner_dns_record:
44 state: present
45 zone: foo.com
46 record: new.foo.com
47 type: A
48 ttl: 7200
49 value: 1.1.1.1
50 hetzner_token: access_token
51
52 - name: Add A record using prefix for www.example.com
53 community.dns.hetzner_dns_record:
54 state: present
55 zone_name: example.com
56 prefix: www
57 type: A
58 value: 198.51.100.25
59 hetzner_token: "{{ lookup('env', 'HETZNER_DNS_TOKEN') }}"
60
61 - name: Remove a new.foo.com A record
62 community.dns.hetzner_dns_record:
63 state: absent
64 zone_name: foo.com
65 record: new.foo.com
66 type: A
67 ttl: 7200
68 value: 2.2.2.2
69 hetzner_token: access_token
70 """
71
72 RETURN = r"""
73 zone_id:
74 description: The ID of the zone.
75 type: str
76 returned: success
77 sample: 23
78 """
79
80 from ansible.module_utils.basic import AnsibleModule
81
82 from ansible_collections.community.dns.plugins.module_utils._argspec import (
83 ModuleOptionProvider,
84 )
85 from ansible_collections.community.dns.plugins.module_utils._hetzner.api import (
86 create_hetzner_api,
87 create_hetzner_argument_spec,
88 create_hetzner_provider_information,
89 )
90 from ansible_collections.community.dns.plugins.module_utils._http import (
91 ModuleHTTPHelper,
92 )
93 from ansible_collections.community.dns.plugins.module_utils._module.record import (
94 create_module_argument_spec,
95 run_module,
96 )
97
98
99 def main() -> None:
100 provider_information = create_hetzner_provider_information()
101 argument_spec = create_hetzner_argument_spec()
102 argument_spec.merge(
103 create_module_argument_spec(provider_information=provider_information)
104 )
105 module = AnsibleModule(supports_check_mode=True, **argument_spec.to_kwargs())
106 option_provider = ModuleOptionProvider(module)
107 run_module(
108 module,
109 lambda: create_hetzner_api(option_provider, ModuleHTTPHelper(module)),
110 provider_information=create_hetzner_provider_information(
111 option_provider=option_provider
112 ),
113 )
114
115
116 if __name__ == "__main__":
117 main()