From 4cd95dbcc509ccec5a8b83294a251623c2895d9f Mon Sep 17 00:00:00 2001
From: Christian Berendt <berendt@betacloud-solutions.de>
Date: Mon, 23 May 2016 17:45:52 +0200
Subject: [PATCH] Enable central logging without deploying elasticsearch/kibana

This changed introduces 4 new parameters to be able to use an existing
elasticsearch service for central logging.

* elasticsearch_address - address of elasticsearch server
* elasticsearch_protocol - protocol (HTTP/HTTPS) used by elasticsearch server
* enable_elasticsearch - deploy elasticsearch container
* enable_kibana - deploy kibana container

Closes-bug: #1584861

Change-Id: Ia1ff9ae8b6d9929c3826da02693d1e2fc9ea2522
---
 ansible/group_vars/all.yml                          | 10 ++++++++++
 .../common/templates/heka-elasticsearch.toml.j2     |  2 +-
 ansible/roles/haproxy/templates/haproxy.cfg.j2      |  4 +++-
 ansible/site.yml                                    |  4 ++--
 doc/advanced-configuration.rst                      | 13 +++++++++++++
 5 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml
index 3b5a1ae3ca..abc07680b4 100644
--- a/ansible/group_vars/all.yml
+++ b/ansible/group_vars/all.yml
@@ -243,6 +243,16 @@ enable_nova_fake: "no"
 num_nova_fake_per_node: 5
 
 
+####################
+# Logging options
+####################
+
+elasticsearch_address: "{{ kolla_internal_vip_address }}"
+elasticsearch_protocol: "{{ internal_protocol }}"
+
+enable_elasticsearch: "{{ 'yes' if enable_central_logging | bool }}"
+enable_kibana: "{{ 'yes' if enable_central_logging | bool }}"
+
 ####################
 # RabbitMQ options
 ####################
diff --git a/ansible/roles/common/templates/heka-elasticsearch.toml.j2 b/ansible/roles/common/templates/heka-elasticsearch.toml.j2
index 7b9a351cb5..f3d4b13465 100644
--- a/ansible/roles/common/templates/heka-elasticsearch.toml.j2
+++ b/ansible/roles/common/templates/heka-elasticsearch.toml.j2
@@ -6,7 +6,7 @@ fields = ["Timestamp", "Type", "Logger", "Severity", "Payload", "Pid", "Hostname
 
 [elasticsearch_output]
 type = "ElasticSearchOutput"
-server = "{{ internal_protocol }}://{{ kolla_internal_vip_address }}:{{ elasticsearch_port }}"
+server = "{{ elasticsearch_protocol }}://{{ elasticsearch_address }}:{{ elasticsearch_port }}"
 message_matcher = "Type == 'log'"
 encoder = "elasticsearch_json_encoder"
 use_buffering = true
diff --git a/ansible/roles/haproxy/templates/haproxy.cfg.j2 b/ansible/roles/haproxy/templates/haproxy.cfg.j2
index c808a3da87..d0949ed98d 100644
--- a/ansible/roles/haproxy/templates/haproxy.cfg.j2
+++ b/ansible/roles/haproxy/templates/haproxy.cfg.j2
@@ -364,7 +364,7 @@ listen radosgw_external
 {% endif %}
 {% endif %}
 
-{% if enable_central_logging | bool %}
+{% if enable_kibana | bool %}
 
 userlist kibanauser
   user {{ kibana_user }} insecure-password {{ kibana_password }}
@@ -388,7 +388,9 @@ listen kibana_external
   server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ kibana_server_port }} check inter 2000 rise 2 fall 5
 {% endfor %}
 {% endif %}
+{% endif %}
 
+{% if enable_elasticsearch | bool %}
 listen elasticsearch
   option dontlog-normal
   bind {{ kolla_internal_vip_address }}:{{ elasticsearch_port }}
diff --git a/ansible/site.yml b/ansible/site.yml
index e923d4d390..44c163ae63 100644
--- a/ansible/site.yml
+++ b/ansible/site.yml
@@ -12,7 +12,7 @@
   roles:
     - { role: elasticsearch,
         tags: elasticsearch,
-        when: enable_central_logging | bool }
+        when: enable_elasticsearch | bool }
 
 - hosts:
     - cinder-api
@@ -39,7 +39,7 @@
   roles:
     - { role: kibana,
         tags: kibana,
-        when: enable_central_logging | bool }
+        when: enable_kibana | bool }
 
 - hosts: memcached
   roles:
diff --git a/doc/advanced-configuration.rst b/doc/advanced-configuration.rst
index 9ba0f0d318..789b883ddd 100644
--- a/doc/advanced-configuration.rst
+++ b/doc/advanced-configuration.rst
@@ -194,3 +194,16 @@ adding:
 Note this method is not recommended and generally not tested by the
 Kolla community, but included since sometimes a free IP is not available
 in a testing environment.
+
+External Elasticsearch/Kibana environment
+=========================================
+
+It is possible to use an external Elasticsearch/Kibana environment. To do this
+first disable the deployment of the central logging.
+
+::
+
+    enable_central_logging: "no"
+
+Now you can use the parameter ``elasticsearch_address`` to configure the address
+of the external Elasticsearch environment.