@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -eux
set -euv x
MYTMPDIR = $( mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir' )
trap 'rm -rf "${MYTMPDIR}"' EXIT
@ -12,6 +12,12 @@ echo "This is a test file" > "${TEST_FILE}"
TEST_FILE_1_2 = " ${ MYTMPDIR } /test_file_1_2 "
echo "This is a test file for format 1.2" > " ${ TEST_FILE_1_2 } "
TEST_FILE_ENC_PASSWORD = " ${ MYTMPDIR } /test_file_enc_password "
echo "This is a test file for encrypted with a vault password that is itself vault encrypted" > " ${ TEST_FILE_ENC_PASSWORD } "
TEST_FILE_ENC_PASSWORD_DEFAULT = " ${ MYTMPDIR } /test_file_enc_password_default "
echo "This is a test file for encrypted with a vault password that is itself vault encrypted using --encrypted-vault-id default" > " ${ TEST_FILE_ENC_PASSWORD_DEFAULT } "
TEST_FILE_OUTPUT = " ${ MYTMPDIR } /test_file_output "
TEST_FILE_EDIT = " ${ MYTMPDIR } /test_file_edit "
@ -20,6 +26,20 @@ echo "This is a test file for edit" > "${TEST_FILE_EDIT}"
TEST_FILE_EDIT2 = " ${ MYTMPDIR } /test_file_edit2 "
echo "This is a test file for edit2" > " ${ TEST_FILE_EDIT2 } "
# view the vault encrypted password file
ansible-vault view " $@ " --vault-id vault-password encrypted-vault-password
# encrypt with a password from a vault encrypted password file and multiple vault-ids
# should fail because we dont know which vault id to use to encrypt with
ansible-vault encrypt " $@ " --vault-id vault-password --vault-id encrypted-vault-password " ${ TEST_FILE_ENC_PASSWORD } " && :
WRONG_RC = $?
echo " rc was $WRONG_RC (5 is expected) "
[ $WRONG_RC -eq 5 ]
# try to view the file encrypted with the vault-password we didnt specify
# to verify we didnt choose the wrong vault-id
ansible-vault view " $@ " --vault-id vault-password encrypted-vault-password
FORMAT_1_1_HEADER = "\$ANSIBLE_VAULT;1.1;AES256"
FORMAT_1_2_HEADER = "\$ANSIBLE_VAULT;1.2;AES256"
@ -30,9 +50,6 @@ ansible-vault view "$@" --vault-id vault-password@test-vault-client.py format_1_
# view, using password client script, unknown vault/keyname
ansible-vault view " $@ " --vault-id some_unknown_vault_id@test-vault-client.py format_1_1_AES256.yml && :
WRONG_RC = $?
echo " rc was $WRONG_RC (1 is expected) "
[ $WRONG_RC -eq 1 ]
# Use linux setsid to test without a tty. No setsid if osx/bsd though...
if [ -x " $( command -v setsid) " ] ; then
@ -319,6 +336,37 @@ head -1 "${TEST_FILE_EDIT2}" | grep "${FORMAT_1_2_HEADER};vault_password"
EDITOR = ./faux-editor.py ansible-vault edit " $@ " --vault-password-file vault-password " ${ TEST_FILE_EDIT2 } "
head -1 " ${ TEST_FILE_EDIT2 } " | grep " ${ FORMAT_1_2_HEADER } ;vault_password "
# encrypt with a password from a vault encrypted password file and multiple vault-ids
# should fail because we dont know which vault id to use to encrypt with
ansible-vault encrypt " $@ " --vault-id vault-password --vault-id encrypted-vault-password " ${ TEST_FILE_ENC_PASSWORD } " && :
WRONG_RC = $?
echo " rc was $WRONG_RC (5 is expected) "
[ $WRONG_RC -eq 5 ]
# encrypt with a password from a vault encrypted password file and multiple vault-ids
# but this time specify with --encrypt-vault-id, but specifying vault-id names (instead of default)
# ansible-vault encrypt "$@" --vault-id from_vault_password@vault-password --vault-id from_encrypted_vault_password@encrypted-vault-password --encrypt-vault-id from_encrypted_vault_password "${TEST_FILE_ENC_PASSWORD}"
# try to view the file encrypted with the vault-password we didnt specify
# to verify we didnt choose the wrong vault-id
# ansible-vault view "$@" --vault-id vault-password "${TEST_FILE_ENC_PASSWORD}" && :
# WRONG_RC=$?
# echo "rc was $WRONG_RC (1 is expected)"
# [ $WRONG_RC -eq 1 ]
ansible-vault encrypt " $@ " --vault-id vault-password " ${ TEST_FILE_ENC_PASSWORD } "
# view the file encrypted with a password from a vault encrypted password file
ansible-vault view " $@ " --vault-id vault-password --vault-id encrypted-vault-password " ${ TEST_FILE_ENC_PASSWORD } "
# try to view the file encrypted with a password from a vault encrypted password file but without the password to the password file.
# This should fail with an
ansible-vault view " $@ " --vault-id encrypted-vault-password " ${ TEST_FILE_ENC_PASSWORD } " && :
WRONG_RC = $?
echo " rc was $WRONG_RC (1 is expected) "
[ $WRONG_RC -eq 1 ]
# test playbooks using vaulted files
ansible-playbook test_vault.yml -i ../../inventory -v " $@ " --vault-password-file vault-password --list-tasks