Skip to content

Commit b1e0bc7

Browse files
committed
Refactor Ansible vault argument handling to support local and Docker 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.
1 parent 936dd97 commit b1e0bc7

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/actions/vault.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ action_vault(){
66
"${vault_run_command[@]}" --help | sed 's/ansible-vault/spin vault/g'
77
}
88

9-
# Read the vault arguments into an array
10-
read -r -a vault_args < <(set_ansible_vault_args)
11-
129
# Check if ansible-vault is installed locally
1310
if [[ $(command -v ansible-vault) ]]; then
1411
vault_run_command=("ansible-vault")
@@ -18,6 +15,9 @@ action_vault(){
1815
run_type="docker"
1916
fi
2017

18+
# Read the vault arguments into an array
19+
read -r -a vault_args < <(set_ansible_vault_args "$run_type")
20+
2121
# Check if any argument is '--help'
2222
for arg in "$@"; do
2323
if [[ "$arg" == "--help" ]]; then

lib/functions.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,7 @@ send_to_upgrade_script () {
13301330
set_ansible_vault_args() {
13311331
local vault_args=()
13321332
local variable_file=".spin.yml"
1333+
local run_type="${1:-docker}"
13331334

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

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

0 commit comments

Comments
 (0)