From edc7c4ddee3122f356ba8f8b9438fecb7a8ad95e Mon Sep 17 00:00:00 2001 From: Alexandre Chouinard Date: Thu, 5 Dec 2019 15:42:15 -0500 Subject: [PATCH] Fix encrypt command output when using --stdin-name (#65122) * Fix encrypt command output when using --stdin-name Add a new line after reading input if input doesn't end with a new line * Only print is we're in a tty * Add changelog fragment --- .../65122-fix-encrypt_string-stdin-name-ouput-tty.yml | 2 ++ lib/ansible/cli/vault.py | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 changelogs/fragments/65122-fix-encrypt_string-stdin-name-ouput-tty.yml diff --git a/changelogs/fragments/65122-fix-encrypt_string-stdin-name-ouput-tty.yml b/changelogs/fragments/65122-fix-encrypt_string-stdin-name-ouput-tty.yml new file mode 100644 index 00000000000..975f806236c --- /dev/null +++ b/changelogs/fragments/65122-fix-encrypt_string-stdin-name-ouput-tty.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-vault - Fix ``encrypt_string`` output in a tty when using ``--sdtin-name`` option (https://github.com/ansible/ansible/issues/65121) diff --git a/lib/ansible/cli/vault.py b/lib/ansible/cli/vault.py index 1b4b69db90a..6ea330ab4ef 100644 --- a/lib/ansible/cli/vault.py +++ b/lib/ansible/cli/vault.py @@ -318,6 +318,9 @@ class VaultCLI(CLI): if stdin_text == '': raise AnsibleOptionsError('stdin was empty, not encrypting') + if sys.stdout.isatty() and not stdin_text.endswith("\n"): + display.display("\n") + b_plaintext = to_bytes(stdin_text) # defaults to None