From fbc47e60e1ce0f371c3f9e4350d5581c98d7b393 Mon Sep 17 00:00:00 2001
From: xiaojueguan <xiaojueguan@gmail.com>
Date: Fri, 8 May 2020 14:27:21 +0800
Subject: [PATCH] Remove post_config from the Kibana role
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Since at least Stein, there is no visible effect from these tasks.
The Kibana dashboard seems to be working exactly the same,
greeting user on the first use with "please configure my index".
I tested on both Ubuntu and CentOS.
In new E*K stack (Ussuri+, CentOS8+) it even causes play errors.

Co-authored-by: Radosław Piliszek <radoslaw.piliszek@gmail.com>
Change-Id: Iafc6986cce9cbaa0ea9e219ca85d7d01a61308cf
Closes-Bug: #1799689
---
 ansible/roles/kibana/defaults/main.yml        | 10 ---
 ansible/roles/kibana/tasks/deploy.yml         |  2 -
 ansible/roles/kibana/tasks/post_config.yml    | 89 -------------------
 .../notes/bug-1799689-c8612c73649ac483.yaml   |  5 ++
 4 files changed, 5 insertions(+), 101 deletions(-)
 delete mode 100644 ansible/roles/kibana/tasks/post_config.yml
 create mode 100644 releasenotes/notes/bug-1799689-c8612c73649ac483.yaml

diff --git a/ansible/roles/kibana/defaults/main.yml b/ansible/roles/kibana/defaults/main.yml
index baeea951b5..5ca8cbb47f 100644
--- a/ansible/roles/kibana/defaults/main.yml
+++ b/ansible/roles/kibana/defaults/main.yml
@@ -35,16 +35,6 @@ kibana_elasticsearch_shard_timeout: 0
 kibana_elasticsearch_ssl_verify: false
 
 
-####################
-# Default index
-####################
-kibana_default_index_pattern: "{{ kibana_log_prefix }}-*"
-kibana_default_index:
-  title: "{{ kibana_default_index_pattern }}"
-  timeFieldName: "@timestamp"
-kibana_default_index_options:
-  index.mapper.dynamic: true
-
 ####################
 # Docker
 ####################
diff --git a/ansible/roles/kibana/tasks/deploy.yml b/ansible/roles/kibana/tasks/deploy.yml
index 747e7f665d..375dcad19b 100644
--- a/ansible/roles/kibana/tasks/deploy.yml
+++ b/ansible/roles/kibana/tasks/deploy.yml
@@ -3,5 +3,3 @@
 
 - name: Flush handlers
   meta: flush_handlers
-
-- include_tasks: post_config.yml
diff --git a/ansible/roles/kibana/tasks/post_config.yml b/ansible/roles/kibana/tasks/post_config.yml
deleted file mode 100644
index 15cf0b645f..0000000000
--- a/ansible/roles/kibana/tasks/post_config.yml
+++ /dev/null
@@ -1,89 +0,0 @@
----
-- name: Wait for kibana port
-  wait_for:
-    host: "{{ kolla_internal_fqdn }}"
-    port: "{{ kibana_server_port }}"
-  run_once: true
-
-- name: Register the kibana index in elasticsearch
-  become: true
-  kolla_toolbox:
-    module_name: uri
-    module_args:
-      url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ elasticsearch_port }}/.kibana"
-      method: PUT
-      body: "{{ kibana_default_index_options | to_json }}"
-      body_format: json
-      status_code: 200, 201, 400
-  register: result
-  failed_when:
-    # If the index already exists, Elasticsearch will respond with a 400 error.
-    - result.status == 400
-    # Format: {"json": {"error": {"type": "index_already_exists_exception"}}}
-    - result.get('json', {}).get('error', {}).get('type') != 'index_already_exists_exception'
-  run_once: true
-
-- name: Wait for kibana to register in elasticsearch
-  become: true
-  kolla_toolbox:
-    module_name: uri
-    module_args:
-      url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ elasticsearch_port }}/.kibana"
-      status_code: 200
-  register: result
-  until: result.status == 200
-  retries: 20
-  delay: 2
-  run_once: true
-
-- name: Change kibana config to set index as defaultIndex
-  vars:
-    kibana_default_index_body:
-      defaultIndex: "{{ kibana_default_index_pattern }}"
-  become: true
-  kolla_toolbox:
-    module_name: uri
-    module_args:
-      url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ elasticsearch_port }}/.kibana/config/*"
-      method: PUT
-      body: "{{ kibana_default_index_body | to_json }}"
-      body_format: json
-      status_code: 200, 201
-  run_once: true
-
-- name: Get kibana default indexes
-  become: true
-  kolla_toolbox:
-    module_name: uri
-    module_args:
-      headers:
-        Content-Type: application/json
-      url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ elasticsearch_port }}/.kibana"
-      method: GET
-  register: kibana_default_indexes
-  run_once: true
-  when: kibana_default_index is defined
-
-- name: Set kibana default indexes fact
-  set_fact:
-    kibana_default_indexes: "{{ kibana_default_indexes.json | default([]) }}"
-  when:
-    - kibana_default_indexes is defined
-  run_once: true
-  connection: local
-
-- name: Add index pattern to kibana
-  become: true
-  kolla_toolbox:
-    module_name: uri
-    module_args:
-      url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ elasticsearch_port }}/.kibana/index-pattern/{{ kibana_default_index_pattern }}"  # noqa 204
-      method: PUT
-      body: "{{ kibana_default_index | to_json }}"
-      body_format: json
-      status_code: 201
-  run_once: true
-  when:
-    - kibana_default_index is defined
-    - kibana_default_indexes is defined
-    - kibana_default_indexes['.kibana']['mappings']['config']['properties']['defaultIndex'] is not defined
diff --git a/releasenotes/notes/bug-1799689-c8612c73649ac483.yaml b/releasenotes/notes/bug-1799689-c8612c73649ac483.yaml
new file mode 100644
index 0000000000..df35740676
--- /dev/null
+++ b/releasenotes/notes/bug-1799689-c8612c73649ac483.yaml
@@ -0,0 +1,5 @@
+---
+fixes:
+  - |
+    Fixes Kibana deployment with the new E*K stack (6+).
+    `LP#1799689 <https://launchpad.net/bugs/1799689>`__
-- 
GitLab