Zuul: retrieve tenant configuration from Gerrit

This is intended to prevent one more chicken-and-egg problem of
delivering Zuul changes. This way, a graceful config reload should be
enough for Zuul to pick up updated tenant (and project!) configuration
once they have hit the master branch in Gerrit.

Change-Id: I890f5db5afafab994e953ac759d057c01c8f0dd0
diff --git a/files/zuul/main.yaml b/files/zuul/main.yaml
deleted file mode 100644
index 08ea938..0000000
--- a/files/zuul/main.yaml
+++ /dev/null
@@ -1,8 +0,0 @@
-# This file is generated by Ansible
-#  DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
-#
-- tenant:
-    name: public
-
-- tenant:
-    name: CzechLight
diff --git a/files/zuul/zuul-fetch-tenants-from-gerrit.sh b/files/zuul/zuul-fetch-tenants-from-gerrit.sh
new file mode 100644
index 0000000..538f01c
--- /dev/null
+++ b/files/zuul/zuul-fetch-tenants-from-gerrit.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+curl -s https://gerrit.cesnet.cz/projects/ci%2fproject-config/branches/master/files/zuul%2ftenants.yaml/content | base64 --decode
diff --git a/files/zuul/zuul.conf b/files/zuul/zuul.conf
index 15eaf14..249a555 100644
--- a/files/zuul/zuul.conf
+++ b/files/zuul/zuul.conf
@@ -13,7 +13,7 @@
 start = true
 
 [scheduler]
-tenant_config = /etc/zuul/main.yaml
+tenant_config_script = /usr/local/bin/zuul-fetch-tenants-from-gerrit.sh
 log_config = /etc/zuul/scheduler-logging.conf
 state_dir = /var/lib/zuul
 
diff --git a/roles/zuul_server/tasks/main.yaml b/roles/zuul_server/tasks/main.yaml
index 35b1d4a..00f9248 100644
--- a/roles/zuul_server/tasks/main.yaml
+++ b/roles/zuul_server/tasks/main.yaml
@@ -46,6 +46,14 @@
     name: zuul
     priv: "ALL"
 
+- name: script for retrieving Zuul tenant configuration from Gerrit
+  copy:
+    dest: /usr/local/bin/zuul-fetch-tenants-from-gerrit.sh
+    src: files/zuul/zuul-fetch-tenants-from-gerrit.sh
+    owner: root
+    group: root
+    mode: 0755
+
 # TODO: this is always marked as 'changed' for some reason...
 - name: Install Zuul
   include_role:
@@ -56,7 +64,7 @@
     zuul_pip_executable: /opt/rh/rh-python36/root/bin/pip
     zuul_pip_extra_args: "--install-option='--install-scripts=/usr/local/bin'"
     zuul_file_zuul_conf_src: files/zuul/zuul.conf
-    zuul_file_main_yaml_src: files/zuul/main.yaml
+    zuul_file_main_yaml_manage: false
 
 - name: Provision Zuul SSH directory
   file: