summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Likins <alikins@redhat.com>2016-11-04 13:28:44 -0400
committerAdrian Likins <alikins@redhat.com>2016-11-16 15:14:07 -0500
commitc09060e8ff95ba4c6713906fe1d122eb6cb32309 (patch)
treeeeadbca7c14a6d96fffb30f42012a6ea965ed996
parentb339d4cfe2bc54a37c7b332f1ca0bc5d79a3b81a (diff)
downloadansible-c09060e8ff95ba4c6713906fe1d122eb6cb32309.tar.gz
Fix 'ansible-vault edit' crash on changed nonascii
ansible-vault edit was attempting to decode the file contents and failing. Fixes #18428
-rw-r--r--lib/ansible/parsing/vault/__init__.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/ansible/parsing/vault/__init__.py b/lib/ansible/parsing/vault/__init__.py
index ff3dafa26d..fcab458fce 100644
--- a/lib/ansible/parsing/vault/__init__.py
+++ b/lib/ansible/parsing/vault/__init__.py
@@ -398,18 +398,18 @@ class VaultEditor:
self._shred_file(tmp_path)
raise
- tmpdata = self.read_data(tmp_path)
+ b_tmpdata = self.read_data(tmp_path)
# Do nothing if the content has not changed
- if existing_data == tmpdata and not force_save:
+ if existing_data == b_tmpdata and not force_save:
self._shred_file(tmp_path)
return
# encrypt new data and write out to tmp
# An existing vaultfile will always be UTF-8,
# so decode to unicode here
- enc_data = self.vault.encrypt(tmpdata.decode())
- self.write_data(enc_data, tmp_path)
+ b_ciphertext = self.vault.encrypt(b_tmpdata)
+ self.write_data(b_ciphertext, tmp_path)
# shuffle tmp file into place
self.shuffle_files(tmp_path, filename)
@@ -420,9 +420,9 @@ class VaultEditor:
# A file to be encrypted into a vaultfile could be any encoding
# so treat the contents as a byte string.
- plaintext = self.read_data(filename)
- ciphertext = self.vault.encrypt(plaintext)
- self.write_data(ciphertext, output_file or filename)
+ b_plaintext = self.read_data(filename)
+ b_ciphertext = self.vault.encrypt(b_plaintext)
+ self.write_data(b_ciphertext, output_file or filename)
def decrypt_file(self, filename, output_file=None):