From 3b4126df5a4097b50975b72dbcc8698880910056 Mon Sep 17 00:00:00 2001
From: Agate <me@agate.blue>
Date: Fri, 24 Apr 2020 10:39:01 +0200
Subject: [PATCH] Fixed some db issues due to delegation

---
 defaults/main.yml |  4 ++--
 tasks/db.yml      | 15 +++++++--------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/defaults/main.yml b/defaults/main.yml
index 5f9fbee..569ce64 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -14,8 +14,8 @@ funkwhale_database_managed: true
 funkwhale_database_local: true
 funkwhale_database_name: funkwhale
 funkwhale_database_user: funkwhale
-# the DB host as per your ansible inventory
-funkwhale_database_host_ansible: localhost
+# the DB host as per your ansible inventory. No delegation is used if left empty
+funkwhale_database_host_ansible:
 # the DB FQDN or IP for funkwhale connector configuration (ex: pg01.local)
 funkwhale_database_host_app: localhost
 funkwhale_database_port: 5432
diff --git a/tasks/db.yml b/tasks/db.yml
index 230bad9..23844b2 100644
--- a/tasks/db.yml
+++ b/tasks/db.yml
@@ -13,26 +13,25 @@
     name: postgresql
     state: started
 
-- name: "Create {{ funkwhale_database_user }} database user on {{ funkwhale_database_host_ansible }} (local / passwordless)"
+- name: "Create {{ funkwhale_database_user }} database user on {{ funkwhale_database_host_ansible or inventory_hostname }} (local / passwordless)"
   become: true
   become_user: postgres
-  when: funkwhale_database_managed and funkwhale_database_host_ansible == 'localhost'
+  when: funkwhale_database_managed and funkwhale_database_host_ansible == none
   postgresql_user:
     name: "{{ funkwhale_database_user }}"
     login_user: postgres
-  delegate_to: "{{ funkwhale_database_host_ansible }}"
 
 - name: "Create {{ funkwhale_database_user }} database user on {{ funkwhale_database_host_ansible }} (remote / with password)"
   become: true
   become_user: postgres
-  when: funkwhale_database_managed and funkwhale_database_host_ansible != 'localhost'
+  when: funkwhale_database_managed and funkwhale_database_host_ansible != none
   postgresql_user:
     name: "{{ funkwhale_database_user }}"
     password: "{{ funkwhale_database_password }}"
     login_user: postgres
-  delegate_to: "{{ funkwhale_database_host_ansible }}"
+  delegate_to: "{{ funkwhale_database_host_ansible or inventory_hostname }}"
 
-- name: "Create {{ funkwhale_database_name }} database on {{ funkwhale_database_host_ansible }}"
+- name: "Create {{ funkwhale_database_name }} database on {{ funkwhale_database_host_ansible or inventory_hostname}}"
   become: true
   become_user: postgres
   when: funkwhale_database_managed
@@ -42,7 +41,7 @@
     owner: "{{ funkwhale_database_user }}"
     encoding: UTF-8
     template: template0
-  delegate_to: "{{ funkwhale_database_host_ansible }}"
+  delegate_to: "{{ funkwhale_database_host_ansible or inventory_hostname }}"
 
 - name: set up pgsql extensions
   become: yes
@@ -55,6 +54,6 @@
   loop: ['unaccent', 'citext']
   loop_control:
     loop_var: myext
-  delegate_to: "{{ funkwhale_database_host_ansible }}"
+  delegate_to: "{{ funkwhale_database_host_ansible or inventory_hostname }}"
 
 ...
-- 
GitLab