ansible-vault encrypt_string: fix --output to write into file (#76856)

Fixes #75101
Fixes #59590
pull/77375/head^2
Martin Krizek 3 years ago committed by GitHub
parent 18ed2c64e5
commit f501b579e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- "ansible-vault encrypt_string - fix ``--output`` option to correctly write encrypted string into given file (https://github.com/ansible/ansible/issues/75101)"

@ -376,12 +376,15 @@ class VaultCLI(CLI):
# Format the encrypted strings and any corresponding stderr output
outputs = self._format_output_vault_strings(b_plaintext_list, vault_id=self.encrypt_vault_id)
b_outs = []
for output in outputs:
err = output.get('err', None)
out = output.get('out', '')
if err:
sys.stderr.write(err)
print(out)
b_outs.append(to_bytes(out))
self.editor.write_data(b'\n'.join(b_outs), context.CLIARGS['output_file'] or '-')
if sys.stdout.isatty():
display.display("Encryption successful", stderr=True)

@ -344,6 +344,8 @@ ansible-vault encrypt_string "$@" --vault-password-file "${NEW_VAULT_PASSWORD}"
# write to file
ansible-vault encrypt_string "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" --name "blippy" "a test string names blippy" --output "${MYTMPDIR}/enc_string_test_file"
[ -f "${MYTMPDIR}/enc_string_test_file" ];
# test ansible-vault edit with a faux editor
ansible-vault encrypt "$@" --vault-password-file vault-password "${TEST_FILE_EDIT}"

Loading…
Cancel
Save