2020-03-19 00:43:41 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
|
|
|
|
2020-03-19 22:45:06 +00:00
|
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
|
|
|
2020-03-21 23:33:12 +00:00
|
|
|
dokku-ansible-playbook-validate-dependencies() {
|
2020-03-20 21:25:59 +00:00
|
|
|
if ! command -v "ansible-playbook" &>/dev/null; then
|
|
|
|
log-fail "Missing ansible-playbook, run dokku plugin:install-dependencies"
|
|
|
|
fi
|
|
|
|
}
|
2020-03-20 00:00:19 +00:00
|
|
|
|
2020-03-21 23:33:12 +00:00
|
|
|
dokku-ansible-playbook-run() {
|
2020-03-19 23:11:35 +00:00
|
|
|
local app="$1"
|
|
|
|
local play_path="$2"
|
|
|
|
local requirements="$3"
|
2020-03-22 01:06:23 +00:00
|
|
|
local vault_file="$DOKKU_LIB_ROOT/data/ansible/.vault-pass.sh"
|
2020-03-19 00:43:41 +00:00
|
|
|
|
2020-03-21 23:33:12 +00:00
|
|
|
dokku-ansible-playbook-validate-dependencies
|
2020-03-20 21:25:59 +00:00
|
|
|
|
2020-03-19 01:05:30 +00:00
|
|
|
if [[ ! -f "$play_path" ]]; then
|
2020-03-19 22:42:53 +00:00
|
|
|
dokku_col_log_info1_quiet "$play_path not found or executable bit not set"
|
2020-03-19 00:43:41 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-03-19 01:19:57 +00:00
|
|
|
if [[ -f "$requirements" ]]; then
|
2020-03-19 22:42:53 +00:00
|
|
|
dokku_col_log_info1_quiet "$requirements file found"
|
2020-03-20 23:08:58 +00:00
|
|
|
ansible-galaxy install --role-file "$requirements"
|
2020-03-19 00:43:41 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-20 21:49:39 +00:00
|
|
|
dokku_col_log_info1_quiet "Copying library modules into place"
|
2020-03-20 22:39:31 +00:00
|
|
|
mkdir -p $DOKKU_ROOT/.ansible/{roles,plugins/modules}
|
2020-03-20 22:27:21 +00:00
|
|
|
cp -R $DOKKU_ROOT/.ansible/roles/*/library/* $DOKKU_ROOT/.ansible/plugins/modules
|
2020-03-20 21:49:39 +00:00
|
|
|
|
2020-03-21 00:51:32 +00:00
|
|
|
local args="--inventory $(hostname), --connection local"
|
2020-03-21 00:47:43 +00:00
|
|
|
|
2020-03-21 00:22:21 +00:00
|
|
|
if [[ -f "$vault_file" ]]; then
|
|
|
|
dokku_col_log_info1_quiet "$vault_file file found"
|
2020-03-22 00:54:19 +00:00
|
|
|
args="${args} --vault-password-file $vault_file"
|
2020-03-21 00:22:21 +00:00
|
|
|
fi
|
2020-03-21 00:47:43 +00:00
|
|
|
|
|
|
|
dokku_col_log_info1_quiet "$play_path file found"
|
2020-03-22 01:15:20 +00:00
|
|
|
ansible-playbook \
|
|
|
|
--extra-vars "dokku_lib_root=$DOKKU_LIB_ROOT" \
|
2020-03-22 01:24:38 +00:00
|
|
|
$args $play_path
|
2020-03-19 00:43:41 +00:00
|
|
|
}
|
2020-03-21 23:33:12 +00:00
|
|
|
|
|
|
|
dokku-ansible-playbook-vault-pass-cmd() {
|
|
|
|
#shellcheck disable=SC2034
|
|
|
|
declare desc="insert new vault password for encrypt/decrypt of passwords"
|
2020-03-22 01:06:23 +00:00
|
|
|
local vault_file="$DOKKU_LIB_ROOT/data/ansible/.vault-pass.sh"
|
2020-03-21 23:33:12 +00:00
|
|
|
|
2020-03-22 00:54:19 +00:00
|
|
|
if [[ -f $vault_file ]]; then
|
2020-03-21 23:33:12 +00:00
|
|
|
dokku_col_log_info1_quiet "Vault password already in place"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-03-21 23:51:48 +00:00
|
|
|
read -srp "Vault password: " vault_password
|
2020-03-21 23:33:12 +00:00
|
|
|
|
2020-03-22 00:58:04 +00:00
|
|
|
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"
|
2020-03-21 23:33:12 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-22 00:54:19 +00:00
|
|
|
dokku_col_log_info1_quiet "Generating $vault_file"
|
|
|
|
|
|
|
|
{ echo "#!/bin/bash";
|
|
|
|
echo "";
|
|
|
|
echo "set -eu -o pipefail";
|
|
|
|
echo "";
|
|
|
|
echo "echo \"$vault_password\""; } > "$vault_file"
|
|
|
|
|
2020-03-22 01:02:13 +00:00
|
|
|
chmod +x "$vault_file"
|
2020-03-21 23:33:12 +00:00
|
|
|
}
|