2016-10-12 21:57:53 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eux
|
|
|
|
|
2017-02-24 15:30:54 +00:00
|
|
|
MYTMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
|
|
|
|
trap 'rm -rf "${MYTMPDIR}"' EXIT
|
2016-11-22 15:56:37 +00:00
|
|
|
|
2017-02-24 15:30:54 +00:00
|
|
|
# create a test file
|
|
|
|
TEST_FILE="${MYTMPDIR}/test_file"
|
|
|
|
echo "This is a test file" > "${TEST_FILE}"
|
|
|
|
|
2017-04-18 17:09:02 +00:00
|
|
|
TEST_FILE_OUTPUT="${MYTMPDIR}/test_file_output"
|
|
|
|
|
2017-02-24 15:30:54 +00:00
|
|
|
# encrypt it
|
|
|
|
ansible-vault encrypt "$@" --vault-password-file vault-password "${TEST_FILE}"
|
|
|
|
|
|
|
|
ansible-vault view "$@" --vault-password-file vault-password "${TEST_FILE}"
|
|
|
|
|
|
|
|
ansible-vault decrypt "$@" --vault-password-file vault-password "${TEST_FILE}"
|
|
|
|
|
|
|
|
# new password file for rekeyed file
|
|
|
|
NEW_VAULT_PASSWORD="${MYTMPDIR}/new-vault-password"
|
|
|
|
echo "newpassword" > "${NEW_VAULT_PASSWORD}"
|
|
|
|
|
|
|
|
ansible-vault encrypt "$@" --vault-password-file vault-password "${TEST_FILE}"
|
|
|
|
|
|
|
|
ansible-vault rekey "$@" --vault-password-file vault-password --new-vault-password-file "${NEW_VAULT_PASSWORD}" "${TEST_FILE}"
|
|
|
|
|
|
|
|
ansible-vault view "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" "${TEST_FILE}"
|
|
|
|
|
|
|
|
ansible-vault decrypt "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" "${TEST_FILE}"
|
|
|
|
|
2017-04-18 17:09:02 +00:00
|
|
|
# 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}"
|
|
|
|
|
2017-02-24 15:30:54 +00:00
|
|
|
ansible-vault encrypt_string "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" "a test string"
|
|
|
|
|
|
|
|
ansible-vault encrypt_string "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" --name "blippy" "a test string names blippy"
|
|
|
|
|
|
|
|
|
|
|
|
# from stdin
|
|
|
|
ansible-vault encrypt_string "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" < "${TEST_FILE}"
|
|
|
|
|
|
|
|
ansible-vault encrypt_string "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" --stdin-name "the_var_from_stdin" < "${TEST_FILE}"
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
|
|
|
|
|
|
|
# test playbooks using vaulted files
|
2016-10-12 21:57:53 +00:00
|
|
|
ansible-playbook test_vault.yml -i ../../inventory -v "$@" --vault-password-file vault-password --list-tasks
|
|
|
|
ansible-playbook test_vault.yml -i ../../inventory -v "$@" --vault-password-file vault-password --list-hosts
|
|
|
|
ansible-playbook test_vault.yml -i ../../inventory -v "$@" --vault-password-file vault-password --syntax-check
|
|
|
|
ansible-playbook test_vault.yml -i ../../inventory -v "$@" --vault-password-file vault-password
|
|
|
|
ansible-playbook test_vault_embedded.yml -i ../../inventory -v "$@" --vault-password-file vault-password --syntax-check
|
|
|
|
ansible-playbook test_vault_embedded.yml -i ../../inventory -v "$@" --vault-password-file vault-password
|
2016-11-22 15:56:37 +00:00
|
|
|
ansible-playbook test_vaulted_inventory.yml -i vaulted.inventory -v "$@" --vault-password-file vault-password
|
2017-06-07 18:16:03 +00:00
|
|
|
ansible-playbook test_vaulted_template.yml -i ../../inventory -v "$@" --vault-password-file vault-password
|