Debian Codegraph @

ansible_collections/community/general/plugins/modules/utm_dns_host.py

raw
1 #!/usr/bin/python
2
3 # Copyright (c) 2018, Johannes Brunswicker <[email protected]>
4 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6 from __future__ import annotations
7
8 DOCUMENTATION = r"""
9 module: utm_dns_host
10
11 author:
12 - Johannes Brunswicker (@MatrixCrawler)
13
14 short_description: Create, update or destroy DNS entry in Sophos UTM
15
16 description:
17 - Create, update or destroy a DNS entry in SOPHOS UTM.
18 - This module needs to have the REST Ability of the UTM to be activated.
19 attributes:
20 check_mode:
21 support: none
22 diff_mode:
23 support: none
24
25 options:
26 name:
27 type: str
28 description:
29 - The name of the object that identifies the entry.
30 required: true
31 address:
32 type: str
33 description:
34 - The IPV4 Address of the entry. Can be left empty for automatic resolving.
35 default: 0.0.0.0
36 address6:
37 type: str
38 description:
39 - The IPV6 Address of the entry. Can be left empty for automatic resolving.
40 default: "::"
41 comment:
42 type: str
43 description:
44 - An optional comment to add to the DNS host object.
45 default: ''
46 hostname:
47 type: str
48 description:
49 - The hostname for the DNS host object.
50 interface:
51 type: str
52 description:
53 - The reference name of the interface to use. If not provided the default interface is used.
54 default: ''
55 resolved:
56 description:
57 - Whether the hostname's ipv4 address is already resolved or not.
58 default: false
59 type: bool
60 resolved6:
61 description:
62 - Whether the hostname's ipv6 address is already resolved or not.
63 default: false
64 type: bool
65 timeout:
66 type: int
67 description:
68 - The timeout for the UTM to resolve the IP address for the hostname again.
69 default: 0
70
71 extends_documentation_fragment:
72 - community.general._utm
73 - community.general._attributes
74 """
75
76 EXAMPLES = r"""
77 - name: Create UTM dns host entry
78 community.general.utm_dns_host:
79 utm_host: sophos.host.name
80 utm_token: abcdefghijklmno1234
81 name: TestDNSEntry
82 hostname: testentry.some.tld
83 state: present
84
85 - name: Remove UTM dns host entry
86 community.general.utm_dns_host:
87 utm_host: sophos.host.name
88 utm_token: abcdefghijklmno1234
89 name: TestDNSEntry
90 state: absent
91 """
92
93 RETURN = r"""
94 result:
95 description: The utm object that was created.
96 returned: success
97 type: complex
98 contains:
99 _ref:
100 description: The reference name of the object.
101 type: str
102 _locked:
103 description: Whether or not the object is currently locked.
104 type: bool
105 name:
106 description: The name of the object.
107 type: str
108 address:
109 description: The ipv4 address of the object.
110 type: str
111 address6:
112 description: The ipv6 address of the object.
113 type: str
114 comment:
115 description: The comment string.
116 type: str
117 hostname:
118 description: The hostname of the object.
119 type: str
120 interface:
121 description: The reference name of the interface the object is associated with.
122 type: str
123 resolved:
124 description: Whether the ipv4 address is resolved or not.
125 type: bool
126 resolved6:
127 description: Whether the ipv6 address is resolved or not.
128 type: bool
129 timeout:
130 description: The timeout until a new resolving is attempted.
131 type: int
132 """
133
134 from ansible_collections.community.general.plugins.module_utils._utm_utils import UTM, UTMModule
135
136
137 def main():
138 endpoint = "network/dns_host"
139 key_to_check_for_changes = ["comment", "hostname", "interface"]
140 module = UTMModule(
141 argument_spec=dict(
142 name=dict(type="str", required=True),
143 address=dict(type="str", default="0.0.0.0"),
144 address6=dict(type="str", default="::"),
145 comment=dict(type="str", default=""),
146 hostname=dict(type="str"),
147 interface=dict(type="str", default=""),
148 resolved=dict(type="bool", default=False),
149 resolved6=dict(type="bool", default=False),
150 timeout=dict(type="int", default=0),
151 )
152 )
153 try:
154 UTM(module, endpoint, key_to_check_for_changes).execute()
155 except Exception as e:
156 module.fail_json(msg=f"{e}")
157
158
159 if __name__ == "__main__":
160 main()