Move to post-extract approach

This commit is contained in:
Luke Murphy 2020-03-19 23:29:59 +01:00
parent ce40247d0a
commit 791fb893ee
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
5 changed files with 32 additions and 16 deletions

View File

@ -5,30 +5,30 @@ Run ansible playbooks during deployment.
## Requirements
* dokku 0.19.13+
* [dokku-supply-config](https://github.com/dokku-community/dokku-supply-config)
* Debian based system (uses `apt` package manager for dependencies)
## Installation
```shell
$ dokku plugin:install https://github.com/josegonzalez/dokku-supply-config.git
$ dokku plugin:install https://github.com/decentral1se/dokku-ansible-playbook.git
```
## Usage
All files must be placed within the `.dokku/ansible` folder of your git repository.
All files must be placed within the `ansible` folder of your git repository.
* `requirements.yml`: what role dependencies to download before running your plays.
The following hooks are supported (add `.yml` to the hook name in `.dokku/ansible`):
The following hooks are supported (add `.yml` to the hook name in `ansible`):
* `pre-deploy`
* `post-deploy`
Everything is copied into `$DOKKU_LIB_ROOT/data/ansible/$APP` on the `post-extract` hook.
## Example
### .dokku/ansible/requirements.yml
### ansible/requirements.yml
```yaml
---
@ -36,7 +36,7 @@ The following hooks are supported (add `.yml` to the hook name in `.dokku/ansibl
version: v2020.3.15
```
### .dokku/ansible/pre-deploy.yml
### ansible/pre-deploy.yml
```yaml
---

View File

@ -7,15 +7,15 @@ function run_playbook() {
local requirements="$2"
if [[ ! -f "$play_path" ]]; then
echo " $play_path not found or executable bit not set"
echo "-----> $play_path not found or executable bit not set"
exit 0
fi
if [[ -f "$requirements" ]]; then
echo " $requirements file found"
echo "-----> $requirements file found"
ansible-galaxy install -fr "$requirements"
fi
echo " $play_path file found"
ansible-playbook -i 127.0.0.1, -c local -v "$play_path"
echo "-----> $play_path file found"
ansible-playbook -i 127.0.0.1, -c local "$play_path"
}

View File

@ -3,9 +3,10 @@
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
APP="$1"
PLAYBOOK="$DOKKU_ROOT/$APP/ansible/post-deploy.yml"
REQUIREMENTS="$DOKKU_ROOT/$APP/ansible/requirements.yml"
PLAYBOOK="$DOKKU_LIB_ROOT/data/ansible/$APP/post-deploy.yml"
REQUIREMENTS="$DOKKU_LIB_ROOT/data/ansible/$APP/requirements.yml"
. $(dirname "$0")/functions
echo "-----> Running post-deploy ansible playbook"
. $(dirname "$0")/functions
run_playbook "$PLAYBOOK" "$REQUIREMENTS"

14
post-extract Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
APP="$1"; verify_app_name "$APP"
TMP_WORK_DIR="$2"
pushd "$TMP_WORK_DIR" >/dev/null
cp -r "$TMP_WORK_DIR/ansible/*" "$DOKKU_LIB_ROOT/data/ansible/$APP"
popd >/dev/null

View File

@ -3,9 +3,10 @@
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
APP="$1"
PLAYBOOK="$DOKKU_ROOT/$APP/ansible/post-deploy.yml"
REQUIREMENTS="$DOKKU_ROOT/$APP/ansible/requirements.yml"
PLAYBOOK="$DOKKU_LIB_ROOT/data/ansible/$APP/pre-deploy.yml"
REQUIREMENTS="$DOKKU_LIB_ROOT/data/ansible/$APP/requirements.yml"
. $(dirname "$0")/functions
echo "-----> Running pre-deploy ansible playbook"
. $(dirname "$0")/functions
run_playbook "$PLAYBOOK" "$REQUIREMENTS"