76 lines
2.2 KiB
Bash
Executable File
76 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
|
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
|
|
dokku-ansible-playbook-validate-dependencies() {
|
|
if ! command -v "ansible-playbook" &>/dev/null; then
|
|
log-fail "Missing ansible-playbook, run dokku plugin:install-dependencies"
|
|
fi
|
|
}
|
|
|
|
dokku-ansible-playbook-run() {
|
|
local app="$1"
|
|
local play_path="$2"
|
|
local requirements="$3"
|
|
local vault_file="$DOKKU_LIB_ROOT/data/ansible/.vault-pass.sh"
|
|
|
|
dokku-ansible-playbook-validate-dependencies
|
|
|
|
if [[ ! -f "$play_path" ]]; then
|
|
dokku_col_log_info1_quiet "$play_path not found or executable bit not set"
|
|
exit 0
|
|
fi
|
|
|
|
if [[ -f "$requirements" ]]; then
|
|
dokku_col_log_info1_quiet "$requirements file found"
|
|
ansible-galaxy install --role-file "$requirements"
|
|
fi
|
|
|
|
dokku_col_log_info1_quiet "Copying library modules into place"
|
|
mkdir -p $DOKKU_ROOT/.ansible/{roles,plugins/modules}
|
|
cp -R $DOKKU_ROOT/.ansible/roles/*/library/* $DOKKU_ROOT/.ansible/plugins/modules
|
|
|
|
local args="--inventory $(hostname), --connection local"
|
|
|
|
if [[ -f "$vault_file" ]]; then
|
|
dokku_col_log_info1_quiet "$vault_file file found"
|
|
args="${args} --vault-password-file $vault_file"
|
|
fi
|
|
|
|
dokku_col_log_info1_quiet "$play_path file found"
|
|
dokku_col_log_info1_quiet "running ansible-playbook with $args"
|
|
ansible-playbook \
|
|
--extra-vars "dokku_lib_root=$DOKKU_LIB_ROOT" \
|
|
$args $play_path
|
|
}
|
|
|
|
dokku-ansible-playbook-vault-pass-cmd() {
|
|
#shellcheck disable=SC2034
|
|
declare desc="insert new vault password for encrypt/decrypt of passwords"
|
|
local vault_file="$DOKKU_LIB_ROOT/data/ansible/.vault-pass.sh"
|
|
|
|
if [[ -f $vault_file ]]; then
|
|
dokku_col_log_info1_quiet "Vault password already in place"
|
|
exit 0
|
|
fi
|
|
|
|
read -srp "Vault password: " vault_password
|
|
|
|
if [[ ! -d "$DOKKU_LIB_ROOT/data/ansible" ]]; then
|
|
dokku_col_log_info1_quiet "Creating $DOKKU_LIB_ROOT/data/ansible"
|
|
mkdir -p "$DOKKU_LIB_ROOT/data/ansible"
|
|
fi
|
|
|
|
dokku_col_log_info1_quiet "Generating $vault_file"
|
|
|
|
{ echo "#!/bin/bash";
|
|
echo "";
|
|
echo "set -eu -o pipefail";
|
|
echo "";
|
|
echo "echo \"$vault_password\""; } > "$vault_file"
|
|
|
|
chmod +x "$vault_file"
|
|
}
|