#!/usr/bin/env bash

set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x

source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"

function run_playbook() {
  local play_path="$1"
  local requirements="$2"

  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 -fr "$requirements"
  fi

  dokku_col_log_info1_quiet "$play_path file found"
  ansible-playbook -i 127.0.0.1, -c local "$play_path"
}
