From 7c8d869f7cc738d6cb1bc1a4144f615f2774a087 Mon Sep 17 00:00:00 2001 From: staticsafe Date: Mon, 27 Nov 2017 12:12:42 -0500 Subject: [PATCH] Switch over to using a variable for database name Also addition to PostgreSQL role to drop any existing database with the same name to allow for playbook reruns. --- roles/group_vars/all.sample | 4 ++++ roles/mastodon-config/templates/.env.production.sample | 2 +- roles/mastodon-postgresql/tasks/main.yml | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 roles/group_vars/all.sample diff --git a/roles/group_vars/all.sample b/roles/group_vars/all.sample new file mode 100644 index 0000000..5cd8ecc --- /dev/null +++ b/roles/group_vars/all.sample @@ -0,0 +1,4 @@ +# Specify the PostgreSQL database name you want to use for Mastodon +# Please note that the playbook will drop this database in preparation for Mastodon's +# database setup process. +DB_NAME: diff --git a/roles/mastodon-config/templates/.env.production.sample b/roles/mastodon-config/templates/.env.production.sample index eefccd0..5d56041 100644 --- a/roles/mastodon-config/templates/.env.production.sample +++ b/roles/mastodon-config/templates/.env.production.sample @@ -9,7 +9,7 @@ DB_HOST=/var/run/postgresql # Your PostgreSQL user DB_USER=mastodon # Your PostgreSQL DB name -DB_NAME=mastodon_production +DB_NAME={{ DB_NAME }} # Leave DB password empty DB_PASS= # Your DB_PORT diff --git a/roles/mastodon-postgresql/tasks/main.yml b/roles/mastodon-postgresql/tasks/main.yml index 570031e..da13b67 100644 --- a/roles/mastodon-postgresql/tasks/main.yml +++ b/roles/mastodon-postgresql/tasks/main.yml @@ -15,3 +15,9 @@ state: present become: true become_user: postgres +- name: Drop any existing database that may exist with the same name + postgresql_db: + name: {{ DB_NAME }} + state: absent + become: true + become_user: postgres