Optimize reconfiguration for elasticsearch
Co-Authored-By: caoyuan <cao.yuan@99cloud.net> Change-Id: Ica989c7f70810d2cf98c0920ec264a311473e5b1 Partially-implements: blueprint better-reconfigure
This commit is contained in:
parent
692c6986f2
commit
ef81297e09
@ -1,4 +1,16 @@
|
|||||||
---
|
---
|
||||||
|
elasticsearch_services:
|
||||||
|
elasticsearch:
|
||||||
|
container_name: elasticsearch
|
||||||
|
group: elasticsearch
|
||||||
|
enabled: true
|
||||||
|
image: "{{ elasticsearch_image_full }}"
|
||||||
|
volumes:
|
||||||
|
- "{{ node_config_directory }}/elasticsearch/:{{ container_config_directory }}/"
|
||||||
|
- "/etc/localtime:/etc/localtime:ro"
|
||||||
|
- "elasticsearch:/var/lib/elasticsearch/data"
|
||||||
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# Elasticsearch
|
# Elasticsearch
|
||||||
####################
|
####################
|
||||||
|
21
ansible/roles/elasticsearch/handlers/main.yml
Normal file
21
ansible/roles/elasticsearch/handlers/main.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
- name: Restart elasticsearch container
|
||||||
|
vars:
|
||||||
|
service_name: "elasticsearch"
|
||||||
|
service: "{{ elasticsearch_services[service_name] }}"
|
||||||
|
config_json: "{{ elasticsearch_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
|
||||||
|
elasticsearch_conf: "{{ elasticsearch_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
|
||||||
|
elasticsearch_container: "{{ check_elasticsearch_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 elasticsearch_conf.changed | bool
|
||||||
|
or elasticsearch_container.changed | bool
|
@ -1,22 +1,48 @@
|
|||||||
---
|
---
|
||||||
- name: Ensuring config directories exist
|
- name: Ensuring config directories exist
|
||||||
file:
|
file:
|
||||||
path: "{{ node_config_directory }}/{{ item }}"
|
path: "{{ node_config_directory }}/{{ item.key }}"
|
||||||
state: "directory"
|
state: "directory"
|
||||||
recurse: yes
|
recurse: yes
|
||||||
with_items:
|
when: inventory_hostname in groups[item.value.group]
|
||||||
- "elasticsearch"
|
with_dict: "{{ elasticsearch_services }}"
|
||||||
|
|
||||||
- name: Copying over config.json files for services
|
- name: Copying over config.json files for services
|
||||||
template:
|
template:
|
||||||
src: "{{ item }}.json.j2"
|
src: "{{ item.key }}.json.j2"
|
||||||
dest: "{{ node_config_directory }}/{{ item }}/config.json"
|
dest: "{{ node_config_directory }}/{{ item.key }}/config.json"
|
||||||
with_items:
|
register: elasticsearch_config_jsons
|
||||||
- "elasticsearch"
|
when:
|
||||||
|
- inventory_hostname in groups[item.value.group]
|
||||||
|
- item.value.enabled | bool
|
||||||
|
with_dict: "{{ elasticsearch_services }}"
|
||||||
|
notify:
|
||||||
|
- Restart elasticsearch container
|
||||||
|
|
||||||
- name: Copying over elasticsearch.yml
|
- name: Copying over elasticsearch.yml
|
||||||
template:
|
template:
|
||||||
src: "elasticsearch.yml.j2"
|
src: "elasticsearch.yml.j2"
|
||||||
dest: "{{ node_config_directory }}/{{ item }}/{{ item }}.yml"
|
dest: "{{ node_config_directory }}/{{ item.key }}/{{ item.key }}.yml"
|
||||||
with_items:
|
register: elasticsearch_confs
|
||||||
- "elasticsearch"
|
when:
|
||||||
|
- inventory_hostname in groups[item.value.group]
|
||||||
|
- item.value.enabled | bool
|
||||||
|
with_dict: "{{ elasticsearch_services }}"
|
||||||
|
notify:
|
||||||
|
- Restart elasticsearch container
|
||||||
|
|
||||||
|
- name: Check elasticsearch 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_elasticsearch_containers
|
||||||
|
when:
|
||||||
|
- action != "config"
|
||||||
|
- inventory_hostname in groups[item.value.group]
|
||||||
|
- item.value.enabled | bool
|
||||||
|
with_dict: "{{ elasticsearch_services }}"
|
||||||
|
notify:
|
||||||
|
- Restart elasticsearch container
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
---
|
---
|
||||||
- include: config.yml
|
- include: config.yml
|
||||||
|
|
||||||
- include: start.yml
|
- name: Flush handlers
|
||||||
|
meta: flush_handlers
|
||||||
|
@ -3,4 +3,8 @@
|
|||||||
kolla_docker:
|
kolla_docker:
|
||||||
action: "pull_image"
|
action: "pull_image"
|
||||||
common_options: "{{ docker_common_options }}"
|
common_options: "{{ docker_common_options }}"
|
||||||
image: "{{ elasticsearch_image_full }}"
|
image: "{{ item.value.image }}"
|
||||||
|
when:
|
||||||
|
- inventory_hostname in groups[item.value.group]
|
||||||
|
- item.value.enabled | bool
|
||||||
|
with_dict: "{{ elasticsearch_services }}"
|
||||||
|
@ -1,64 +1,2 @@
|
|||||||
---
|
---
|
||||||
- name: Ensuring the containers up
|
- include: deploy.yml
|
||||||
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: elasticsearch, group: elasticsearch }
|
|
||||||
|
|
||||||
- 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: elasticsearch, group: elasticsearch }
|
|
||||||
|
|
||||||
# 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: elasticsearch, group: elasticsearch }
|
|
||||||
|
|
||||||
- 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: elasticsearch, group: elasticsearch }]
|
|
||||||
- "{{ 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: elasticsearch, group: elasticsearch }]
|
|
||||||
- "{{ container_envs.results }}"
|
|
||||||
- "{{ check_results.results }}"
|
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Starting Elasticsearch container
|
|
||||||
kolla_docker:
|
|
||||||
action: "start_container"
|
|
||||||
common_options: "{{ docker_common_options }}"
|
|
||||||
image: "{{ elasticsearch_image_full }}"
|
|
||||||
name: "elasticsearch"
|
|
||||||
volumes:
|
|
||||||
- "{{ node_config_directory }}/elasticsearch/:{{ container_config_directory }}/"
|
|
||||||
- "/etc/localtime:/etc/localtime:ro"
|
|
||||||
- "elasticsearch:/var/lib/elasticsearch/data"
|
|
||||||
when: inventory_hostname in groups ['elasticsearch']
|
|
@ -1,4 +1,5 @@
|
|||||||
---
|
---
|
||||||
- include: config.yml
|
- include: config.yml
|
||||||
|
|
||||||
- include: start.yml
|
- name: Flush handlers
|
||||||
|
meta: flush_handlers
|
||||||
|
Loading…
Reference in New Issue
Block a user