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/README.md

80 lines
2.5 KiB
Markdown
Raw Normal View History

2020-03-19 00:13:54 +00:00
# dokku-ansible-playbook
Run ansible playbooks during deployment.
This plugin can be useful when you need to provision your server before or after a deployment of your application (or on [any hook](https://github.com/dokku/dokku/blob/master/docs/development/plugin-triggers.md), just raise an issue and let's add it) and you prefer to use Ansible instead of Bash. For example, you make use of the [ansible-dokku](https://github.com/dokku/ansible-dokku/) roles.
2020-03-19 00:13:54 +00:00
## Requirements
2020-03-21 00:08:57 +00:00
- dokku 0.19.13+
- Debian based system (uses `apt` package manager for installing dependencies)
2020-03-19 00:13:54 +00:00
## Installation
```shell
$ dokku plugin:install https://github.com/decentral1se/dokku-ansible-playbook.git
$ dokku plugin:install-dependencies
2020-03-19 00:13:54 +00:00
```
## Usage
2020-03-21 00:26:35 +00:00
All files must be placed within the `ansible` folder of your git repository. Everything is copied into `$DOKKU_LIB_ROOT/data/ansible/$APP` on the `post-extract` hook. Dokku will make sure that your Ansible plays are run on the right hook against the Dokku server localhost.
2020-03-19 00:13:54 +00:00
2020-03-21 00:08:57 +00:00
- `requirements.yml`: what role dependencies to download before running your plays.
- `pre-deploy.yml`: play run before a deployment
- `post-deploy.yml`: play run after a deployment
2020-03-19 00:55:49 +00:00
2020-03-21 00:08:57 +00:00
## Passwords
2020-03-21 00:26:35 +00:00
You can place a `ansible/.vault.sh` script that produces your [Ansible Vault](https://docs.ansible.com/ansible/latest/user_guide/vault.html password. This file will be copied over to `$DOKKU_LIB_ROOT/data/ansible/$APP` and locked down with the correct read-only permissions for the Dokku user account. This will then be used as the [Ansible Vault](https://docs.ansible.com/ansible/latest/user_guide/vault.html) password file which can be used to decrypt secrets.
Don't forget to `chmod +x` it and also **add this file to your `.gitignore`**, you've been warned!
Here's an example `ansible/.vault.sh` file.
2020-03-21 00:08:57 +00:00
```bash
#!/bin/bash
set -eu -o pipefail
echo "my-cool-vault-password"
```
So, if you then encrypt a secret:
```bash
$ ansible-vault \
encrypt_string \
--vault-password-file ansible/.vault.sh \
--name mysecretname \
mysecretvalue
```
2020-03-21 00:26:35 +00:00
You can place this output in your plays and it can be successfully decrypted on the remote Dokku host.
2020-03-19 22:29:59 +00:00
2020-03-19 00:55:49 +00:00
## Example
2020-03-19 22:29:59 +00:00
### ansible/requirements.yml
2020-03-19 00:55:49 +00:00
```yaml
---
- src: dokku_bot.ansible_dokku
version: v2020.3.15
```
2020-03-19 22:29:59 +00:00
### ansible/pre-deploy.yml
2020-03-19 00:55:49 +00:00
```yaml
---
- hosts: all
tasks:
2020-03-21 00:08:57 +00:00
- name: Configure the foobar environment
dokku_config:
app: foobar
restart: false
config:
FOO: BAR
become: true
become_user: dokku
2020-03-19 00:55:49 +00:00
```