1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

udm_dns_record: minor refactor (#6382)

* udm_dns_record: minor refactor

* remove unused import

* improve ptr_record zone validation

* add changelog frag

* undo zone validation change as it breaks for IPv6 addresses
This commit is contained in:
Alexei Znamensky 2023-04-24 00:01:53 +12:00 committed by GitHub
parent ad6ff9b0c5
commit 3e338a1cca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 31 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- udm_dns_record - minor refactor to the code (https://github.com/ansible-collections/community.general/pull/6382).

View file

@ -97,19 +97,9 @@ EXAMPLES = '''
RETURN = '''#''' RETURN = '''#'''
HAVE_UNIVENTION = False
HAVE_IPADDRESS = False
try:
from univention.admin.handlers.dns import (
forward_zone,
reverse_zone,
)
HAVE_UNIVENTION = True
except ImportError:
pass
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import missing_required_lib from ansible_collections.community.general.plugins.module_utils import deps
from ansible_collections.community.general.plugins.module_utils.univention_umc import ( from ansible_collections.community.general.plugins.module_utils.univention_umc import (
umc_module_for_add, umc_module_for_add,
umc_module_for_edit, umc_module_for_edit,
@ -118,27 +108,26 @@ from ansible_collections.community.general.plugins.module_utils.univention_umc i
config, config,
uldap, uldap,
) )
try:
with deps.declare("univention", msg="This module requires univention python bindings"):
from univention.admin.handlers.dns import (
forward_zone,
reverse_zone,
)
with deps.declare("ipaddress"):
import ipaddress import ipaddress
HAVE_IPADDRESS = True
except ImportError:
pass
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
type=dict(required=True, type=dict(required=True, type='str'),
type='str'), zone=dict(required=True, type='str'),
zone=dict(required=True, name=dict(required=True, type='str'),
type='str'), data=dict(default={}, type='dict'),
name=dict(required=True, state=dict(default='present', choices=['present', 'absent'], type='str')
type='str'),
data=dict(default={},
type='dict'),
state=dict(default='present',
choices=['present', 'absent'],
type='str')
), ),
supports_check_mode=True, supports_check_mode=True,
required_if=([ required_if=([
@ -146,8 +135,7 @@ def main():
]) ])
) )
if not HAVE_UNIVENTION: deps.validate(module, "univention")
module.fail_json(msg="This module requires univention python bindings")
type = module.params['type'] type = module.params['type']
zone = module.params['zone'] zone = module.params['zone']
@ -159,8 +147,8 @@ def main():
workname = name workname = name
if type == 'ptr_record': if type == 'ptr_record':
if not HAVE_IPADDRESS: deps.validate(module, "ipaddress")
module.fail_json(msg=missing_required_lib('ipaddress'))
try: try:
if 'arpa' not in zone: if 'arpa' not in zone:
raise Exception("Zone must be reversed zone for ptr_record. (e.g. 1.1.192.in-addr.arpa)") raise Exception("Zone must be reversed zone for ptr_record. (e.g. 1.1.192.in-addr.arpa)")
@ -196,7 +184,7 @@ def main():
'(zoneName={0})'.format(zone), '(zoneName={0})'.format(zone),
scope='domain', scope='domain',
) )
if len(so) == 0: if not so == 0:
raise Exception("Did not find zone '{0}' in Univention".format(zone)) raise Exception("Did not find zone '{0}' in Univention".format(zone))
obj = umc_module_for_add('dns/{0}'.format(type), container, superordinate=so[0]) obj = umc_module_for_add('dns/{0}'.format(type), container, superordinate=so[0])
else: else: