Compatibilité python2

This commit is contained in:
Benjamin Bohard 2021-10-26 11:31:21 +02:00
parent d6656ab1a9
commit 53f82ae1f1
1 changed files with 15 additions and 0 deletions

View File

@ -50,6 +50,7 @@ diff:
sample: ['activer_ajout_hosts: non => oui']
'''
import sys
from ansible.module_utils.basic import AnsibleModule
from creole.loader import creole_loader, config_save_values
@ -62,6 +63,18 @@ def process_value(variable, value):
raise Exception('Variable {} is not multi'.format(variable))
return value
def yml_params_to_unicode(param):
def convert_param(param):
if isinstance(param, str):
return param.decode('utf-8')
if isinstance(param, list):
return [convert_param(p) for p in param]
if isinstance(param, dict):
return {convert_param(key): convert_param(value) for key,value in param.items()}
return param
return convert_param(param)
def run_module():
# define available arguments/parameters a user can pass to the module
@ -97,6 +110,8 @@ def run_module():
d = c.cfgimpl_get_description()
diff = []
c.cfgimpl_get_settings().remove('disabled')
if sys.version_info < (3,):
module.params['variables'] = yml_params_to_unicode(module.params['variables'])
variables = {}
for variable in module.params['variables']: