From c497c8c4e195f658618e85bb346e49c9860aa018 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman <rjeffman@redhat.com> Date: Thu, 30 Sep 2021 21:16:18 -0300 Subject: [PATCH] host: Use IPAAnsibleModule method to validate arguments. Use the IPAAnsibleModule.params_fail_if_used method to validate arguments provided by user. --- plugins/modules/ipahost.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/plugins/modules/ipahost.py b/plugins/modules/ipahost.py index 93403001..aa94ccec 100644 --- a/plugins/modules/ipahost.py +++ b/plugins/modules/ipahost.py @@ -530,6 +530,7 @@ def check_parameters( # pylint: disable=unused-argument userclass, auth_ind, requires_pre_auth, ok_as_delegate, ok_to_auth_as_delegate, force, reverse, ip_address, update_dns, update_password): + invalid = [] if state == "present": if action == "member": # certificate, managedby_host, principal, @@ -539,11 +540,6 @@ def check_parameters( # pylint: disable=unused-argument "userclass", "auth_ind", "requires_pre_auth", "ok_as_delegate", "ok_to_auth_as_delegate", "force", "reverse", "update_dns", "update_password"] - for x in invalid: - if vars()[x] is not None: - module.fail_json( - msg="Argument '%s' can not be used with action " - "'%s'" % (x, action)) if state == "absent": invalid = ["description", "locality", "location", "platform", "os", @@ -551,11 +547,6 @@ def check_parameters( # pylint: disable=unused-argument "userclass", "auth_ind", "requires_pre_auth", "ok_as_delegate", "ok_to_auth_as_delegate", "force", "reverse", "update_password"] - for x in invalid: - if vars()[x] is not None: - module.fail_json( - msg="Argument '%s' can not be used with state '%s'" % - (x, state)) if action == "host": invalid = [ "certificate", "managedby_host", "principal", @@ -565,11 +556,8 @@ def check_parameters( # pylint: disable=unused-argument "allow_retrieve_keytab_host", "allow_retrieve_keytab_hostgroup" ] - for x in invalid: - if vars()[x] is not None: - module.fail_json( - msg="Argument '%s' can only be used with action " - "'member' for state '%s'" % (x, state)) + + module.params_fail_used_invalid(invalid, state, action) # pylint: disable=unused-argument -- GitLab