From 13eed1ba57a1b43724654e80c7f2d36aca427af1 Mon Sep 17 00:00:00 2001 From: caoyuan Date: Fri, 20 Jan 2017 17:59:51 +0800 Subject: [PATCH] Optimize reconfiguration for kibana Change-Id: Ic4beb20361644b42dbed82fcffb7446c00f84e87 Partially-implements: blueprint better-reconfigure --- ansible/roles/kibana/defaults/main.yml | 14 +++++ ansible/roles/kibana/handlers/main.yml | 21 +++++++ ansible/roles/kibana/tasks/config.yml | 50 +++++++++++++---- ansible/roles/kibana/tasks/deploy.yml | 3 +- ansible/roles/kibana/tasks/pull.yml | 6 +- ansible/roles/kibana/tasks/reconfigure.yml | 64 +--------------------- ansible/roles/kibana/tasks/start.yml | 11 ---- ansible/roles/kibana/tasks/upgrade.yml | 3 +- 8 files changed, 84 insertions(+), 88 deletions(-) create mode 100644 ansible/roles/kibana/handlers/main.yml delete mode 100644 ansible/roles/kibana/tasks/start.yml diff --git a/ansible/roles/kibana/defaults/main.yml b/ansible/roles/kibana/defaults/main.yml index e35e2f1e71..fde66bfda6 100644 --- a/ansible/roles/kibana/defaults/main.yml +++ b/ansible/roles/kibana/defaults/main.yml @@ -1,4 +1,18 @@ --- +project_name: "Kibana" + +kibana_services: + kibana: + container_name: "kibana" + image: "{{ kibana_image_full }}" + enabled: true + group: "kibana" + volumes: + - "{{ node_config_directory }}/kibana/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + + #################### # Kibana #################### diff --git a/ansible/roles/kibana/handlers/main.yml b/ansible/roles/kibana/handlers/main.yml new file mode 100644 index 0000000000..3cf27af666 --- /dev/null +++ b/ansible/roles/kibana/handlers/main.yml @@ -0,0 +1,21 @@ +--- +- name: Restart kibana container + vars: + service_name: "kibana" + service: "{{ kibana_services[service_name] }}" + config_json: "{{ kibana_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + kibana_conf: "{{ kibana_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + kibana_container: "{{ check_kibana_containers.results|selectattr('item.key', 'equalto', service_name)|first }}" + kolla_docker: + action: "recreate_or_restart_container" + common_options: "{{ docker_common_options }}" + name: "{{ service.container_name }}" + image: "{{ service.image }}" + volumes: "{{ service.volumes }}" + when: + - action != "config" + - inventory_hostname in groups[service.group] + - service.enabled | bool + - config_json.changed | bool + or kibana_conf.changed | bool + or kibana_container.changed | bool diff --git a/ansible/roles/kibana/tasks/config.yml b/ansible/roles/kibana/tasks/config.yml index edccb229c5..c3d3cfa5be 100644 --- a/ansible/roles/kibana/tasks/config.yml +++ b/ansible/roles/kibana/tasks/config.yml @@ -1,22 +1,50 @@ --- - name: Ensuring kibana config directories exist file: - path: "{{ node_config_directory }}/{{ item }}" + path: "{{ node_config_directory }}/{{ item.key }}" state: "directory" recurse: yes - with_items: - - "kibana" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ kibana_services }}" - name: Copying over config.json files for services template: - src: "{{ item }}.json.j2" - dest: "{{ node_config_directory }}/{{ item }}/config.json" - with_items: - - "kibana" + src: "{{ item.key }}.json.j2" + dest: "{{ node_config_directory }}/{{ item.key }}/config.json" + register: kibana_config_json + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ kibana_services }}" + notify: + - Restart kibana container - name: Copying over Kibana configuration file template: - src: "{{ item }}.yml.j2" - dest: "{{ node_config_directory }}/{{ item }}/{{ item }}.yml" - with_items: - - "kibana" + src: "{{ item.key }}.yml.j2" + dest: "{{ node_config_directory }}/{{ item.key }}/{{ item.key }}.yml" + register: kibana_confs + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ kibana_services }}" + notify: + - Restart kibana container + +- name: Check kibana containers + kolla_docker: + action: "compare_container" + common_options: "{{ docker_common_options }}" + name: "{{ item.value.container_name }}" + image: "{{ item.value.image }}" + volumes: "{{ item.value.volumes }}" + register: check_kibana_containers + when: + - action != "config" + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ kibana_services }}" + notify: + - Restart kibana container diff --git a/ansible/roles/kibana/tasks/deploy.yml b/ansible/roles/kibana/tasks/deploy.yml index 1f16915ad9..dd26ecc34d 100644 --- a/ansible/roles/kibana/tasks/deploy.yml +++ b/ansible/roles/kibana/tasks/deploy.yml @@ -1,4 +1,5 @@ --- - include: config.yml -- include: start.yml +- name: Flush handlers + meta: flush_handlers diff --git a/ansible/roles/kibana/tasks/pull.yml b/ansible/roles/kibana/tasks/pull.yml index afe39cd3e6..e4835b78ab 100644 --- a/ansible/roles/kibana/tasks/pull.yml +++ b/ansible/roles/kibana/tasks/pull.yml @@ -3,4 +3,8 @@ kolla_docker: action: "pull_image" common_options: "{{ docker_common_options }}" - image: "{{ kibana_image_full }}" + image: "{{ item.value.image }}" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ kibana_services }}" diff --git a/ansible/roles/kibana/tasks/reconfigure.yml b/ansible/roles/kibana/tasks/reconfigure.yml index 54cfea05d5..e078ef1318 100644 --- a/ansible/roles/kibana/tasks/reconfigure.yml +++ b/ansible/roles/kibana/tasks/reconfigure.yml @@ -1,64 +1,2 @@ --- -- name: Ensuring the containers up - kolla_docker: - name: "{{ item.name }}" - action: "get_container_state" - register: container_state - failed_when: container_state.Running == false - when: inventory_hostname in groups[item.group] - with_items: - - { name: kibana, group: kibana } - -- include: config.yml - -- name: Check the configs - command: docker exec {{ item.name }} /usr/local/bin/kolla_set_configs --check - changed_when: false - failed_when: false - register: check_results - when: inventory_hostname in groups[item.group] - with_items: - - { name: kibana, group: kibana } - -# NOTE(jeffrey4l): when config_strategy == 'COPY_ALWAYS' -# and container env['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE', -# just remove the container and start again -- name: Containers config strategy - kolla_docker: - name: "{{ item.name }}" - action: "get_container_env" - register: container_envs - when: inventory_hostname in groups[item.group] - with_items: - - { name: kibana, group: kibana } - -- name: Remove the containers - kolla_docker: - name: "{{ item[0]['name'] }}" - action: "remove_container" - register: remove_containers - when: - - config_strategy == "COPY_ONCE" or item[1]['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE' - - item[2]['rc'] == 1 - - inventory_hostname in groups[item[0]['group']] - with_together: - - [{ name: kibana, group: kibana }] - - "{{ container_envs.results }}" - - "{{ check_results.results }}" - -- include: start.yml - when: remove_containers.changed - -- name: Restart containers - kolla_docker: - name: "{{ item[0]['name'] }}" - action: "restart_container" - when: - - config_strategy == 'COPY_ALWAYS' - - item[1]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE' - - item[2]['rc'] == 1 - - inventory_hostname in groups[item[0]['group']] - with_together: - - [{ name: kibana, group: kibana }] - - "{{ container_envs.results }}" - - "{{ check_results.results }}" +- include: deploy.yml diff --git a/ansible/roles/kibana/tasks/start.yml b/ansible/roles/kibana/tasks/start.yml deleted file mode 100644 index 239e892c2f..0000000000 --- a/ansible/roles/kibana/tasks/start.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Starting Kibana container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ kibana_image_full }}" - name: "kibana" - volumes: - - "{{ node_config_directory }}/kibana/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" diff --git a/ansible/roles/kibana/tasks/upgrade.yml b/ansible/roles/kibana/tasks/upgrade.yml index 1f16915ad9..dd26ecc34d 100644 --- a/ansible/roles/kibana/tasks/upgrade.yml +++ b/ansible/roles/kibana/tasks/upgrade.yml @@ -1,4 +1,5 @@ --- - include: config.yml -- include: start.yml +- name: Flush handlers + meta: flush_handlers