mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Junos_config unicode (#23369)
* Try to handle unicode output more sensibly * Appears I'm getting latin1 instead Ugh.
This commit is contained in:
parent
1c61b9bae7
commit
689b93bf14
4 changed files with 8 additions and 8 deletions
|
@ -24,6 +24,7 @@ from ansible.module_utils.basic import env_fallback, return_values
|
||||||
from ansible.module_utils.netconf import send_request, children
|
from ansible.module_utils.netconf import send_request, children
|
||||||
from ansible.module_utils.netconf import discard_changes, validate
|
from ansible.module_utils.netconf import discard_changes, validate
|
||||||
from ansible.module_utils.six import string_types
|
from ansible.module_utils.six import string_types
|
||||||
|
from ansible.module_utils._text import to_text
|
||||||
|
|
||||||
ACTIONS = frozenset(['merge', 'override', 'replace', 'update', 'set'])
|
ACTIONS = frozenset(['merge', 'override', 'replace', 'update', 'set'])
|
||||||
JSON_ACTIONS = frozenset(['merge', 'override', 'update'])
|
JSON_ACTIONS = frozenset(['merge', 'override', 'update'])
|
||||||
|
@ -111,7 +112,7 @@ def load_configuration(module, candidate=None, action='merge', rollback=None, fo
|
||||||
if format == 'xml':
|
if format == 'xml':
|
||||||
cfg.append(fromstring(candidate))
|
cfg.append(fromstring(candidate))
|
||||||
else:
|
else:
|
||||||
cfg.text = candidate
|
cfg.text = to_text(candidate, encoding='latin1')
|
||||||
else:
|
else:
|
||||||
cfg.append(candidate)
|
cfg.append(candidate)
|
||||||
return send_request(module, obj)
|
return send_request(module, obj)
|
||||||
|
@ -163,7 +164,7 @@ def get_diff(module):
|
||||||
reply = get_configuration(module, compare=True, format='text')
|
reply = get_configuration(module, compare=True, format='text')
|
||||||
output = reply.find('.//configuration-output')
|
output = reply.find('.//configuration-output')
|
||||||
if output is not None:
|
if output is not None:
|
||||||
return output.text
|
return to_text(output.text, encoding='latin1').strip()
|
||||||
|
|
||||||
def load_config(module, candidate, warnings, action='merge', commit=False, format='xml',
|
def load_config(module, candidate, warnings, action='merge', commit=False, format='xml',
|
||||||
comment=None, confirm=False, confirm_timeout=None):
|
comment=None, confirm=False, confirm_timeout=None):
|
||||||
|
@ -180,7 +181,6 @@ def load_config(module, candidate, warnings, action='merge', commit=False, forma
|
||||||
diff = get_diff(module)
|
diff = get_diff(module)
|
||||||
|
|
||||||
if diff:
|
if diff:
|
||||||
diff = str(diff).strip()
|
|
||||||
if commit:
|
if commit:
|
||||||
commit_configuration(module, confirm=confirm, comment=comment,
|
commit_configuration(module, confirm=confirm, comment=comment,
|
||||||
confirm_timeout=confirm_timeout)
|
confirm_timeout=confirm_timeout)
|
||||||
|
|
|
@ -195,6 +195,7 @@ from ansible.module_utils.junos import junos_argument_spec
|
||||||
from ansible.module_utils.junos import check_args as junos_check_args
|
from ansible.module_utils.junos import check_args as junos_check_args
|
||||||
from ansible.module_utils.netconf import send_request
|
from ansible.module_utils.netconf import send_request
|
||||||
from ansible.module_utils.six import string_types
|
from ansible.module_utils.six import string_types
|
||||||
|
from ansible.module_utils._text import to_text, to_native
|
||||||
|
|
||||||
if sys.version_info < (2, 7):
|
if sys.version_info < (2, 7):
|
||||||
from xml.parsers.expat import ExpatError
|
from xml.parsers.expat import ExpatError
|
||||||
|
@ -238,7 +239,7 @@ def filter_delete_statements(module, candidate):
|
||||||
if match is None:
|
if match is None:
|
||||||
# Could not find configuration-set in reply, perhaps device does not support it?
|
# Could not find configuration-set in reply, perhaps device does not support it?
|
||||||
return candidate
|
return candidate
|
||||||
config = str(match.text)
|
config = to_native(match.text, encoding='latin1')
|
||||||
|
|
||||||
modified_candidate = candidate[:]
|
modified_candidate = candidate[:]
|
||||||
for index, line in enumerate(candidate):
|
for index, line in enumerate(candidate):
|
||||||
|
@ -331,7 +332,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg='unable to retrieve device configuration')
|
module.fail_json(msg='unable to retrieve device configuration')
|
||||||
|
|
||||||
result['__backup__'] = str(match.text).strip()
|
result['__backup__'] = match.text.strip()
|
||||||
|
|
||||||
if module.params['rollback']:
|
if module.params['rollback']:
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
|
|
|
@ -27,6 +27,7 @@ import glob
|
||||||
from ansible.plugins.action.junos import ActionModule as _ActionModule
|
from ansible.plugins.action.junos import ActionModule as _ActionModule
|
||||||
from ansible.module_utils._text import to_text
|
from ansible.module_utils._text import to_text
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
from ansible.utils.vars import merge_hash
|
from ansible.utils.vars import merge_hash
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
PRIVATE_KEYS_RE = re.compile('__.+__')
|
||||||
|
@ -74,7 +75,7 @@ class ActionModule(_ActionModule):
|
||||||
os.remove(fn)
|
os.remove(fn)
|
||||||
tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time()))
|
tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time()))
|
||||||
filename = '%s/%s_config.%s' % (backup_path, host, tstamp)
|
filename = '%s/%s_config.%s' % (backup_path, host, tstamp)
|
||||||
open(filename, 'w').write(contents)
|
open(filename, 'w').write(to_native(contents, encoding='latin1'))
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
def _handle_template(self):
|
def _handle_template(self):
|
||||||
|
@ -110,4 +111,3 @@ class ActionModule(_ActionModule):
|
||||||
searchpath.append(os.path.dirname(source))
|
searchpath.append(os.path.dirname(source))
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
self._templar.environment.loader.searchpath = searchpath
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
self._task.args['src'] = self._templar.template(template_data)
|
||||||
|
|
||||||
|
|
|
@ -845,7 +845,6 @@ lib/ansible/plugins/action/group_by.py
|
||||||
lib/ansible/plugins/action/ios_template.py
|
lib/ansible/plugins/action/ios_template.py
|
||||||
lib/ansible/plugins/action/iosxr_template.py
|
lib/ansible/plugins/action/iosxr_template.py
|
||||||
lib/ansible/plugins/action/junos.py
|
lib/ansible/plugins/action/junos.py
|
||||||
lib/ansible/plugins/action/junos_config.py
|
|
||||||
lib/ansible/plugins/action/junos_template.py
|
lib/ansible/plugins/action/junos_template.py
|
||||||
lib/ansible/plugins/action/normal.py
|
lib/ansible/plugins/action/normal.py
|
||||||
lib/ansible/plugins/action/nxos.py
|
lib/ansible/plugins/action/nxos.py
|
||||||
|
|
Loading…
Reference in a new issue