From 991bdc5f558467403cc3d993ba5c53b5f89272f9 Mon Sep 17 00:00:00 2001
From: Scott Solkhon <scottsolkhon@gmail.com>
Date: Fri, 29 Nov 2019 21:04:55 +0000
Subject: [PATCH] Fix Prometheus template generation

In a deployment where Prometheus is enabled and
Alertmanager is disabled the task "Copying over
prometheus config file" in
'ansible/roles/prometheus/tasks/config.yml' will
fail to template the Prometheus configuration file
'ansible/roles/prometheus/templates/prometheus.yml.j2'
as the variable 'prometheus_alert_rules' does not
contain the key 'files'. This commit fixes this bug.

Change-Id: Idbe1e52dd3693a6f168d475f9230a253dae64480
Closes-Bug: #1854540
---
 ansible/roles/prometheus/templates/prometheus.yml.j2      | 2 +-
 ...onfig-when-alertmanager-disabled-0090c1570ff4e632.yaml | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 releasenotes/notes/prometheus-config-when-alertmanager-disabled-0090c1570ff4e632.yaml

diff --git a/ansible/roles/prometheus/templates/prometheus.yml.j2 b/ansible/roles/prometheus/templates/prometheus.yml.j2
index f74eadb2bc..2acf076465 100644
--- a/ansible/roles/prometheus/templates/prometheus.yml.j2
+++ b/ansible/roles/prometheus/templates/prometheus.yml.j2
@@ -5,7 +5,7 @@ global:
   external_labels:
     monitor: 'kolla'
 
-{% if prometheus_alert_rules is defined and prometheus_alert_rules.files | length  > 0 %}
+{% if prometheus_alert_rules.files is defined and prometheus_alert_rules.files | length  > 0 %}
 rule_files:
 {% for rule in prometheus_alert_rules.files %}
   - "/etc/prometheus/{{ rule.path | basename }}"
diff --git a/releasenotes/notes/prometheus-config-when-alertmanager-disabled-0090c1570ff4e632.yaml b/releasenotes/notes/prometheus-config-when-alertmanager-disabled-0090c1570ff4e632.yaml
new file mode 100644
index 0000000000..149055552b
--- /dev/null
+++ b/releasenotes/notes/prometheus-config-when-alertmanager-disabled-0090c1570ff4e632.yaml
@@ -0,0 +1,8 @@
+---
+fixes:
+  - |
+    Fixes templating of Prometheus configuration when Alertmanager is disabled.
+    In a deployment where Prometheus is enabled and Alertmanager is disabled the
+    configuration for the Prometheus will fail when templating as the variable
+    `prometheus_alert_rules` does not contain the key `files`. For details
+    please see <https://bugs.launchpad.net/kolla-ansible/+bug/1854540>`__.