ansible_freeipa_module: New functions module_params_get and _afm_convert

The module_params_get function can and should be used as a replacement of
ansible_module.params.get. For Python2 it is needed to convert parameters
to unicode. Otherwise there will be an error in the FreeIPA API command.

The private function _afm_convert has been added to do the conversion
recursively.
This commit is contained in:
Thomas Woerner
2019-10-09 11:58:30 +02:00
parent 3390d6742d
commit b16280455c

View File

@@ -190,3 +190,21 @@ def compare_args_ipa(module, args, ipa):
return False
return True
def _afm_convert(value):
if value is not None:
if isinstance(value, list):
return [_afm_convert(x) for x in value]
elif isinstance(value, dict):
return {_afm_convert(k): _afm_convert(v) for k, v in value.items()}
elif isinstance(value, str):
return to_text(value)
else:
return value
else:
return value
def module_params_get(module, name):
return _afm_convert(module.params.get(name))