Skip to content
Snippets Groups Projects
Commit ed3dd3ea authored by Thomas Woerner's avatar Thomas Woerner
Browse files

config: 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.
parent 3e98ed54
No related branches found
No related tags found
No related merge requests found
...@@ -34,13 +34,9 @@ author: chris procter ...@@ -34,13 +34,9 @@ author: chris procter
short_description: Modify IPA global config options short_description: Modify IPA global config options
description: description:
- Modify IPA global config options - Modify IPA global config options
extends_documentation_fragment:
- ipamodule_base_docs
options: options:
ipaadmin_principal:
description: The admin principal
default: admin
ipaadmin_password:
description: The admin password
required: false
maxusername: maxusername:
description: Set the maximum username length between 1-255 description: Set the maximum username length between 1-255
required: false required: false
...@@ -159,7 +155,7 @@ EXAMPLES = ''' ...@@ -159,7 +155,7 @@ EXAMPLES = '''
tasks: tasks:
- name: return current values of the global configuration options - name: return current values of the global configuration options
ipaconfig: ipaconfig:
ipaadmin_password: password ipaadmin_password: SomeADMINpassword
register: result register: result
- name: display default login shell - name: display default login shell
debug: debug:
...@@ -167,7 +163,7 @@ EXAMPLES = ''' ...@@ -167,7 +163,7 @@ EXAMPLES = '''
- name: set defaultshell and maxusername - name: set defaultshell and maxusername
ipaconfig: ipaconfig:
ipaadmin_password: password ipaadmin_password: SomeADMINpassword
defaultshell: /bin/bash defaultshell: /bin/bash
maxusername: 64 maxusername: 64
''' '''
...@@ -251,14 +247,12 @@ config: ...@@ -251,14 +247,12 @@ config:
''' '''
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, ipalib_errors
temp_kdestroy, valid_creds, api_connect, api_command_no_name, \
compare_args_ipa, module_params_get, ipalib_errors
def config_show(module): def config_show(module):
_result = api_command_no_name(module, "config_show", {}) _result = module.ipa_command_no_name("config_show", {})
return _result["result"] return _result["result"]
...@@ -270,11 +264,9 @@ def gen_args(params): ...@@ -270,11 +264,9 @@ def gen_args(params):
def main(): def main():
ansible_module = AnsibleModule( ansible_module = IPAAnsibleModule(
argument_spec=dict( argument_spec=dict(
# general # general
ipaadmin_principal=dict(type="str", default="admin"),
ipaadmin_password=dict(type="str", required=False, no_log=True),
maxusername=dict(type="int", required=False, maxusername=dict(type="int", required=False,
aliases=['ipamaxusernamelength']), aliases=['ipamaxusernamelength']),
maxhostname=dict(type="int", required=False, maxhostname=dict(type="int", required=False,
...@@ -334,11 +326,6 @@ def main(): ...@@ -334,11 +326,6 @@ def main():
# Get parameters # Get parameters
# general # general
ipaadmin_principal = module_params_get(ansible_module,
"ipaadmin_principal")
ipaadmin_password = module_params_get(ansible_module,
"ipaadmin_password")
field_map = { field_map = {
"maxusername": "ipamaxusernamelength", "maxusername": "ipamaxusernamelength",
"maxhostname": "ipamaxhostnamelength", "maxhostname": "ipamaxhostnamelength",
...@@ -366,7 +353,7 @@ def main(): ...@@ -366,7 +353,7 @@ def main():
params = {} params = {}
for x in field_map: for x in field_map:
val = module_params_get(ansible_module, x) val = ansible_module.params_get(x)
if val is not None: if val is not None:
params[field_map.get(x, x)] = val params[field_map.get(x, x)] = val
...@@ -407,14 +394,11 @@ def main(): ...@@ -407,14 +394,11 @@ def main():
changed = False changed = False
exit_args = {} exit_args = {}
ccache_dir = None
ccache_name = None
res_show = None res_show = None
try:
if not valid_creds(ansible_module, ipaadmin_principal): # Connect to IPA API
ccache_dir, ccache_name = temp_kinit(ipaadmin_principal, with ansible_module.ipa_connect():
ipaadmin_password)
api_connect()
if params: if params:
res_show = config_show(ansible_module) res_show = config_show(ansible_module)
params = { params = {
...@@ -425,10 +409,13 @@ def main(): ...@@ -425,10 +409,13 @@ def main():
and not compare_args_ipa(ansible_module, params, res_show): and not compare_args_ipa(ansible_module, params, res_show):
changed = True changed = True
if not ansible_module.check_mode: if not ansible_module.check_mode:
api_command_no_name(ansible_module, "config_mod", params) try:
ansible_module.ipa_command_no_name("config_mod",
params)
except ipalib_errors.EmptyModlist:
changed = False
else: else:
rawresult = api_command_no_name(ansible_module, "config_show", {}) rawresult = ansible_module.ipa_command_no_name("config_show", {})
result = rawresult['result'] result = rawresult['result']
del result['dn'] del result['dn']
for key, value in result.items(): for key, value in result.items():
...@@ -460,13 +447,6 @@ def main(): ...@@ -460,13 +447,6 @@ def main():
exit_args[k] = (value[0] == "TRUE") exit_args[k] = (value[0] == "TRUE")
else: else:
exit_args[k] = value exit_args[k] = value
except ipalib_errors.EmptyModlist:
changed = False
except Exception as e:
ansible_module.fail_json(msg="%s %s" % (params, str(e)))
finally:
temp_kdestroy(ccache_dir, ccache_name)
# Done # Done
ansible_module.exit_json(changed=changed, config=exit_args) ansible_module.exit_json(changed=changed, config=exit_args)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment