Skip to content

Commit

Permalink
Refactor Ansible vault argument handling to support local and Docker …
Browse files Browse the repository at this point in the history
…runs. The `set_ansible_vault_args` function now accepts a `run_type` parameter, allowing for different vault password file paths based on the execution context. This improves flexibility and clarity in vault management.
  • Loading branch information
jaydrogers committed Dec 18, 2024
1 parent 936dd97 commit b1e0bc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/actions/vault.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ action_vault(){
"${vault_run_command[@]}" --help | sed 's/ansible-vault/spin vault/g'
}

# Read the vault arguments into an array
read -r -a vault_args < <(set_ansible_vault_args)

# Check if ansible-vault is installed locally
if [[ $(command -v ansible-vault) ]]; then
vault_run_command=("ansible-vault")
Expand All @@ -18,6 +15,9 @@ action_vault(){
run_type="docker"
fi

# Read the vault arguments into an array
read -r -a vault_args < <(set_ansible_vault_args "$run_type")

# Check if any argument is '--help'
for arg in "$@"; do
if [[ "$arg" == "--help" ]]; then
Expand Down
7 changes: 6 additions & 1 deletion lib/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@ send_to_upgrade_script () {
set_ansible_vault_args() {
local vault_args=()
local variable_file=".spin.yml"
local run_type="${1:-docker}"

if [[ -f .vault-password ]]; then
# Validate the vault password file using Docker
Expand All @@ -1351,7 +1352,11 @@ set_ansible_vault_args() {
fi
fi

vault_args+=("--vault-password-file" "/ansible/.vault-password")
if [[ "$run_type" == "local" ]]; then
vault_args+=("--vault-password-file" ".vault-password")
else
vault_args+=("--vault-password-file" "/ansible/.vault-password")
fi
elif is_encrypted_with_ansible_vault "$variable_file" || is_encrypted_with_ansible_vault ".spin-inventory.ini"; then
echo "${BOLD}${YELLOW}🔐 '.vault-password' file not found. You will be prompted to enter your vault password.${RESET}" >&2
vault_args+=("--ask-vault-pass")
Expand Down

0 comments on commit b1e0bc7

Please sign in to comment.