Skip to content

Commit

Permalink
add encrypt_file/decrypt_file methods (#301)
Browse files Browse the repository at this point in the history
Kolla ansible supports automatic decryption of vault-encrypted files in site-config.
This is very useful for things like ceph authentication tokens, certificates, and so on.

Note: This CANNOT be used for the SSH key for ansible to connect to a remote host.
See ansible/ansible#22382

Add cc-ansible wrappers for vault encrypt and vault decrypt to make this easy.
  • Loading branch information
msherman64 authored Aug 23, 2024
1 parent fe4ff20 commit 87ee0e1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cc-ansible
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ while [[ $# -gt 0 ]]; do
# Add proper flag support for --check as an option for dry-runs
export EXTRA_OPTS="${EXTRA_OPTS:-} --check"
;;
decrypt_passwords|edit_passwords|help|install_deps|init|view_passwords)
decrypt_passwords|edit_passwords|help|install_deps|init|view_passwords|encrypt_file|decrypt_file)
# Special subcommand!
command="$key"
;;
Expand Down Expand Up @@ -137,6 +137,18 @@ init() {
echo
}

encrypt_file() {
ansible-vault encrypt \
--vault-password-file "$CC_ANSIBLE_VAULT_PASSWORD" \
${POSARGS[@]}
}

decrypt_file() {
ansible-vault decrypt \
--vault-password-file "$CC_ANSIBLE_VAULT_PASSWORD" \
${POSARGS[@]}
}

edit_passwords() {
local tmpfile
local venv_bin_path="${VIRTUALENV}/bin"
Expand Down Expand Up @@ -213,6 +225,10 @@ Examples:
# Update the passwords file for the environment
cc-ansible edit_passwords
# use ansible-vault to encrypt or decrypt a file
cc-ansible encrypt_file path/to/file
cc-ansible decrypt_file path/to/file
USAGE
exit 1
}
Expand Down

0 comments on commit 87ee0e1

Please sign in to comment.