diff --git a/CHANGELOG.md b/CHANGELOG.md index a0849af8731..4cbb66d2a81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ Ansible Changes By Release * removed docs for prematurely added ssh specific pipelining settings * fixed redis cache typo * Fix AttributeError during inventory group deserialization (https://github.com/ansible/ansible/issues/30903) +* Fix 'ansible-vault encrypt --output=-' (https://github.com/ansible/ansible/issues/30550) diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index 4e1bd23aa06..7d285740642 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -406,7 +406,10 @@ class CLI(with_metaclass(ABCMeta, object)): @staticmethod def unfrack_path(option, opt, value, parser): - setattr(parser.values, option.dest, unfrackpath(value)) + if value != '-': + setattr(parser.values, option.dest, unfrackpath(value)) + else: + setattr(parser.values, option.dest, value) @staticmethod def base_parser(usage="", output_opts=False, runas_opts=False, meta_opts=False, runtask_opts=False, vault_opts=False, module_opts=False, diff --git a/test/integration/targets/vault/runme.sh b/test/integration/targets/vault/runme.sh index 4adfa83fbcb..25bd65f69cc 100755 --- a/test/integration/targets/vault/runme.sh +++ b/test/integration/targets/vault/runme.sh @@ -23,6 +23,8 @@ echo "This is a test file for edit2" > "${TEST_FILE_EDIT2}" FORMAT_1_1_HEADER="\$ANSIBLE_VAULT;1.1;AES256" FORMAT_1_2_HEADER="\$ANSIBLE_VAULT;1.2;AES256" +VAULT_PASSWORD_FILE=vault-password + # old format ansible-vault view "$@" --vault-password-file vault-password-ansible format_1_0_AES.yml @@ -202,9 +204,16 @@ ansible-vault view "$@" --vault-id "tmp_new_password@${NEW_VAULT_PASSWORD}" --va ansible-vault decrypt "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" "${TEST_FILE}" # reading/writing to/from stdin/stdin (See https://github.com/ansible/ansible/issues/23567) -ansible-vault encrypt "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" --output="${TEST_FILE_OUTPUT}" < "${TEST_FILE}" -ansible-vault view "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" - < "${TEST_FILE_OUTPUT}" -ansible-vault decrypt "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" --output=- < "${TEST_FILE_OUTPUT}" +ansible-vault encrypt "$@" --vault-password-file "${VAULT_PASSWORD_FILE}" --output="${TEST_FILE_OUTPUT}" < "${TEST_FILE}" +OUTPUT=$(ansible-vault decrypt "$@" --vault-password-file "${VAULT_PASSWORD_FILE}" --output=- < "${TEST_FILE_OUTPUT}") +echo "${OUTPUT}" | grep 'This is a test file' + +OUTPUT_DASH=$(ansible-vault decrypt "$@" --vault-password-file "${VAULT_PASSWORD_FILE}" --output=- "${TEST_FILE_OUTPUT}") +echo "${OUTPUT_DASH}" | grep 'This is a test file' + +OUTPUT_DASH_SPACE=$(ansible-vault decrypt "$@" --vault-password-file "${VAULT_PASSWORD_FILE}" --output - "${TEST_FILE_OUTPUT}") +echo "${OUTPUT_DASH_SPACE}" | grep 'This is a test file' + # test using an empty vault password file ansible-vault view "$@" --vault-password-file empty-password format_1_1_AES256.yml && :