From 47d5f0f0a86d7afe0d4aa768ee35834a505521a5 Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Fri, 4 Nov 2016 13:28:44 -0400 Subject: [PATCH] Fix 'ansible-vault edit' crash on changed nonascii ansible-vault edit was attempting to decode the file contents and failing. Fixes #18428 (cherry picked from commit c09060e8ff95ba4c6713906fe1d122eb6cb32309) --- lib/ansible/parsing/vault/__init__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ansible/parsing/vault/__init__.py b/lib/ansible/parsing/vault/__init__.py index ff3dafa26d9..fcab458fce9 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):