This repository has been archived on 2020-05-08. You can view files and clone it, but cannot push or open issues or pull requests.
dokku-ansible-playbook/functions

46 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
function validate_dependencies() {
if ! command -v "ansible-playbook" &>/dev/null; then
log-fail "Missing ansible-playbook, run dokku plugin:install-dependencies"
fi
}
function run_playbook() {
local app="$1"
local play_path="$2"
local requirements="$3"
validate_dependencies
export ANSIBLE_ROLES_PATH="$DOKKU_LIB_ROOT/data/ansible/$APP/roles"
export ANSIBLE_LIBRARY="$DOKKU_LIB_ROOT/data/ansible/$APP/roles/*/library"
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"
dokku_col_log_info1_quiet "Using $ANSIBLE_ROLES_PATH as role path"
ansible-galaxy \
install \
--force \
--roles-path "$ANSIBLE_ROLES_PATH" \
--role-file "$requirements"
fi
dokku_col_log_info1_quiet "$play_path file found"
dokku_col_log_info1_quiet "Using $ANSIBLE_LIBRARY as module path"
ansible-playbook \
--inventory "$(hostname)", \
--connection local \
--module-path "$ANSIBLE_LIBRARY" \
"$play_path"
}