mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-08-01 04:14:42 +00:00
dnsconfig: Use IPAAnsibleModule class
ipaadmin_variables are handled by IPAAnsibleModule, ansible_module.params_get is used to get the parameters and ansible_module.ipa_connect is used to simplify the module.
This commit is contained in:
@@ -32,14 +32,9 @@ DOCUMENTATION = """
|
|||||||
module: ipadnsconfig
|
module: ipadnsconfig
|
||||||
short description: Manage FreeIPA dnsconfig
|
short description: Manage FreeIPA dnsconfig
|
||||||
description: Manage FreeIPA dnsconfig
|
description: Manage FreeIPA dnsconfig
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- ipamodule_base_docs
|
||||||
options:
|
options:
|
||||||
ipaadmin_principal:
|
|
||||||
description: The admin principal
|
|
||||||
default: admin
|
|
||||||
ipaadmin_password:
|
|
||||||
description: The admin password
|
|
||||||
required: false
|
|
||||||
|
|
||||||
forwarders:
|
forwarders:
|
||||||
description: The list of global DNS forwarders.
|
description: The list of global DNS forwarders.
|
||||||
required: false
|
required: false
|
||||||
@@ -70,6 +65,7 @@ options:
|
|||||||
EXAMPLES = """
|
EXAMPLES = """
|
||||||
# Ensure global DNS forward configuration, allowing PTR record synchronization.
|
# Ensure global DNS forward configuration, allowing PTR record synchronization.
|
||||||
- ipadnsconfig:
|
- ipadnsconfig:
|
||||||
|
ipaadmin_password: SomeADMINpassword
|
||||||
forwarders:
|
forwarders:
|
||||||
- ip_address: 8.8.4.4
|
- ip_address: 8.8.4.4
|
||||||
- ip_address: 2001:4860:4860::8888
|
- ip_address: 2001:4860:4860::8888
|
||||||
@@ -79,6 +75,7 @@ EXAMPLES = """
|
|||||||
|
|
||||||
# Ensure forwarder is absent.
|
# Ensure forwarder is absent.
|
||||||
- ipadnsconfig:
|
- ipadnsconfig:
|
||||||
|
ipaadmin_password: SomeADMINpassword
|
||||||
forwarders:
|
forwarders:
|
||||||
- ip_address: 2001:4860:4860::8888
|
- ip_address: 2001:4860:4860::8888
|
||||||
port: 53
|
port: 53
|
||||||
@@ -86,21 +83,20 @@ EXAMPLES = """
|
|||||||
|
|
||||||
# Disable PTR record synchronization.
|
# Disable PTR record synchronization.
|
||||||
- ipadnsconfig:
|
- ipadnsconfig:
|
||||||
|
ipaadmin_password: SomeADMINpassword
|
||||||
allow_sync_ptr: no
|
allow_sync_ptr: no
|
||||||
|
|
||||||
# Disable global forwarders.
|
# Disable global forwarders.
|
||||||
- ipadnsconfig:
|
- ipadnsconfig:
|
||||||
|
ipaadmin_password: SomeADMINpassword
|
||||||
forward_policy: none
|
forward_policy: none
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RETURN = """
|
RETURN = """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.ansible_freeipa_module import \
|
||||||
from ansible.module_utils.ansible_freeipa_module import temp_kinit, \
|
IPAAnsibleModule, compare_args_ipa, is_ipv4_addr, is_ipv6_addr
|
||||||
temp_kdestroy, valid_creds, api_connect, \
|
|
||||||
api_command_no_name, compare_args_ipa, module_params_get, \
|
|
||||||
is_ipv4_addr, is_ipv6_addr
|
|
||||||
|
|
||||||
|
|
||||||
def find_dnsconfig(module):
|
def find_dnsconfig(module):
|
||||||
@@ -108,7 +104,7 @@ def find_dnsconfig(module):
|
|||||||
"all": True,
|
"all": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
_result = api_command_no_name(module, "dnsconfig_show", _args)
|
_result = module.ipa_command_no_name("dnsconfig_show", _args)
|
||||||
|
|
||||||
if "result" in _result:
|
if "result" in _result:
|
||||||
if _result["result"].get('idnsforwarders', None) is None:
|
if _result["result"].get('idnsforwarders', None) is None:
|
||||||
@@ -170,12 +166,8 @@ def main():
|
|||||||
port=dict(type=int, required=False, default=None)
|
port=dict(type=int, required=False, default=None)
|
||||||
)
|
)
|
||||||
|
|
||||||
ansible_module = AnsibleModule(
|
ansible_module = IPAAnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
# general
|
|
||||||
ipaadmin_principal=dict(type='str', default='admin'),
|
|
||||||
ipaadmin_password=dict(type='str', no_log=True),
|
|
||||||
|
|
||||||
# dnsconfig
|
# dnsconfig
|
||||||
forwarders=dict(type='list', default=None, required=False,
|
forwarders=dict(type='list', default=None, required=False,
|
||||||
options=dict(**forwarder_spec)),
|
options=dict(**forwarder_spec)),
|
||||||
@@ -192,17 +184,12 @@ def main():
|
|||||||
|
|
||||||
ansible_module._ansible_debug = True
|
ansible_module._ansible_debug = True
|
||||||
|
|
||||||
# general
|
# dnsconfig
|
||||||
ipaadmin_principal = module_params_get(ansible_module,
|
forwarders = ansible_module.params_get('forwarders') or []
|
||||||
"ipaadmin_principal")
|
forward_policy = ansible_module.params_get('forward_policy')
|
||||||
ipaadmin_password = module_params_get(ansible_module,
|
allow_sync_ptr = ansible_module.params_get('allow_sync_ptr')
|
||||||
"ipaadmin_password")
|
|
||||||
|
|
||||||
forwarders = module_params_get(ansible_module, 'forwarders') or []
|
state = ansible_module.params_get('state')
|
||||||
forward_policy = module_params_get(ansible_module, 'forward_policy')
|
|
||||||
allow_sync_ptr = module_params_get(ansible_module, 'allow_sync_ptr')
|
|
||||||
|
|
||||||
state = module_params_get(ansible_module, 'state')
|
|
||||||
|
|
||||||
# Check parameters.
|
# Check parameters.
|
||||||
invalid = []
|
invalid = []
|
||||||
@@ -218,13 +205,9 @@ def main():
|
|||||||
# Init
|
# Init
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
ccache_dir = None
|
|
||||||
ccache_name = None
|
# Connect to IPA API
|
||||||
try:
|
with ansible_module.ipa_connect():
|
||||||
if not valid_creds(ansible_module, ipaadmin_principal):
|
|
||||||
ccache_dir, ccache_name = temp_kinit(ipaadmin_principal,
|
|
||||||
ipaadmin_password)
|
|
||||||
api_connect()
|
|
||||||
|
|
||||||
res_find = find_dnsconfig(ansible_module)
|
res_find = find_dnsconfig(ansible_module)
|
||||||
args = gen_args(ansible_module, state, res_find, forwarders,
|
args = gen_args(ansible_module, state, res_find, forwarders,
|
||||||
@@ -234,7 +217,7 @@ def main():
|
|||||||
if not compare_args_ipa(ansible_module, args, res_find):
|
if not compare_args_ipa(ansible_module, args, res_find):
|
||||||
try:
|
try:
|
||||||
if not ansible_module.check_mode:
|
if not ansible_module.check_mode:
|
||||||
api_command_no_name(ansible_module, 'dnsconfig_mod', args)
|
ansible_module.ipa_command_no_name('dnsconfig_mod', args)
|
||||||
# If command did not fail, something changed.
|
# If command did not fail, something changed.
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
@@ -242,12 +225,6 @@ def main():
|
|||||||
msg = str(e)
|
msg = str(e)
|
||||||
ansible_module.fail_json(msg="dnsconfig_mod: %s" % msg)
|
ansible_module.fail_json(msg="dnsconfig_mod: %s" % msg)
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
ansible_module.fail_json(msg=str(e))
|
|
||||||
|
|
||||||
finally:
|
|
||||||
temp_kdestroy(ccache_dir, ccache_name)
|
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
|
|
||||||
ansible_module.exit_json(changed=changed)
|
ansible_module.exit_json(changed=changed)
|
||||||
|
|||||||
Reference in New Issue
Block a user