summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Nalawade <ganesh634@gmail.com>2017-09-04 20:48:35 +0530
committerGitHub <noreply@github.com>2017-09-04 20:48:35 +0530
commit64db935b25bbaad0fe290e3ef39f34e5a3ac5a9c (patch)
treec17c31f0a0e5b02329dccd771b19711b6ea71d46
parent46934c195c916428eae8343bf5c55ed9561f5202 (diff)
downloadansible-64db935b25bbaad0fe290e3ef39f34e5a3ac5a9c.tar.gz
Ensure proper conversion while backing up of junos config (#28958) (#28992)
* Ensure proper conversion while backing up of junos config * Minor changes * Fix review comment * Open config backup file in binary mode (cherry picked from commit cc9ed352dd547b19439cb5c9373f8529e6385314)
-rw-r--r--lib/ansible/module_utils/junos.py4
-rw-r--r--lib/ansible/modules/network/junos/junos_config.py2
-rw-r--r--lib/ansible/plugins/action/junos_config.py5
3 files changed, 6 insertions, 5 deletions
diff --git a/lib/ansible/module_utils/junos.py b/lib/ansible/module_utils/junos.py
index 31bfe8a5d1..c80dc8de38 100644
--- a/lib/ansible/module_utils/junos.py
+++ b/lib/ansible/module_utils/junos.py
@@ -112,7 +112,7 @@ def load_configuration(module, candidate=None, action='merge', rollback=None, fo
if format == 'xml':
cfg.append(fromstring(candidate))
else:
- cfg.text = to_text(candidate, encoding='latin1')
+ cfg.text = to_text(candidate, encoding='latin-1')
else:
cfg.append(candidate)
return send_request(module, obj)
@@ -164,7 +164,7 @@ def get_diff(module):
reply = get_configuration(module, compare=True, format='text')
output = reply.find('.//configuration-output')
if output is not None:
- return to_text(output.text, encoding='latin1').strip()
+ return to_text(output.text, encoding='latin-1').strip()
def load_config(module, candidate, warnings, action='merge', commit=False, format='xml',
comment=None, confirm=False, confirm_timeout=None):
diff --git a/lib/ansible/modules/network/junos/junos_config.py b/lib/ansible/modules/network/junos/junos_config.py
index 05aed0526d..ab883e048d 100644
--- a/lib/ansible/modules/network/junos/junos_config.py
+++ b/lib/ansible/modules/network/junos/junos_config.py
@@ -229,7 +229,7 @@ def filter_delete_statements(module, candidate):
if match is None:
# Could not find configuration-set in reply, perhaps device does not support it?
return candidate
- config = to_native(match.text, encoding='latin1')
+ config = to_native(match.text, encoding='latin-1')
modified_candidate = candidate[:]
for index, line in reversed(list(enumerate(candidate))):
diff --git a/lib/ansible/plugins/action/junos_config.py b/lib/ansible/plugins/action/junos_config.py
index b166f23b3a..b73eb156cb 100644
--- a/lib/ansible/plugins/action/junos_config.py
+++ b/lib/ansible/plugins/action/junos_config.py
@@ -27,7 +27,7 @@ import glob
from ansible.plugins.action.junos import ActionModule as _ActionModule
from ansible.module_utils._text import to_text
from ansible.module_utils.six.moves.urllib.parse import urlsplit
-from ansible.module_utils._text import to_native
+from ansible.module_utils._text import to_bytes
from ansible.utils.vars import merge_hash
PRIVATE_KEYS_RE = re.compile('__.+__')
@@ -75,7 +75,8 @@ class ActionModule(_ActionModule):
os.remove(fn)
tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time()))
filename = '%s/%s_config.%s' % (backup_path, host, tstamp)
- open(filename, 'w').write(to_native(contents, encoding='latin1'))
+ with open(filename, 'wb') as f:
+ f.write(to_bytes(to_text(contents, encoding='latin-1'), encoding='utf-8'))
return filename
def _handle_template(self):