Merge "Optimize reconfiguration for grafana"
This commit is contained in:
commit
b957d2916d
@ -1,6 +1,18 @@
|
||||
---
|
||||
project_name: "grafana"
|
||||
|
||||
grafana_services:
|
||||
grafana:
|
||||
container_name: grafana
|
||||
group: grafana
|
||||
enabled: true
|
||||
image: "{{ grafana_image_full }}"
|
||||
volumes:
|
||||
- "{{ node_config_directory }}/grafana/:{{ container_config_directory }}/:ro"
|
||||
- "/etc/localtime:/etc/localtime:ro"
|
||||
- "grafana:/var/lib/grafana/"
|
||||
- "kolla_logs:/var/log/kolla/"
|
||||
|
||||
####################
|
||||
# Database
|
||||
####################
|
||||
|
21
ansible/roles/grafana/handlers/main.yml
Normal file
21
ansible/roles/grafana/handlers/main.yml
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
- name: Restart grafana container
|
||||
vars:
|
||||
service_name: "grafana"
|
||||
service: "{{ grafana_services[service_name] }}"
|
||||
config_json: "{{ grafana_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
|
||||
grafana_conf: "{{ grafana_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
|
||||
grafana_container: "{{ check_grafana_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 grafana_ini.changed | bool
|
||||
or grafana_container.changed | bool
|
@ -1,27 +1,55 @@
|
||||
---
|
||||
- name: Ensuring config directories exist
|
||||
file:
|
||||
path: "{{ node_config_directory }}/{{ item }}"
|
||||
path: "{{ node_config_directory }}/{{ item.key }}"
|
||||
state: "directory"
|
||||
recurse: yes
|
||||
with_items:
|
||||
- "grafana"
|
||||
when:
|
||||
- inventory_hostname in groups[item.value.group]
|
||||
- item.value.enabled | bool
|
||||
with_dict: "{{ grafana_services }}"
|
||||
|
||||
- name: Copying over config.json files
|
||||
template:
|
||||
src: "{{ item }}.json.j2"
|
||||
dest: "{{ node_config_directory }}/{{ item }}/config.json"
|
||||
with_items:
|
||||
- "grafana"
|
||||
src: "{{ item.key }}.json.j2"
|
||||
dest: "{{ node_config_directory }}/{{ item.key }}/config.json"
|
||||
register: grafana_config_jsons
|
||||
when:
|
||||
- inventory_hostname in groups[item.value.group]
|
||||
- item.value.enabled | bool
|
||||
with_dict: "{{ grafana_services }}"
|
||||
notify:
|
||||
- Restart grafana container
|
||||
|
||||
- name: Copying over grafana.ini
|
||||
merge_configs:
|
||||
vars:
|
||||
service_name: "{{ item }}"
|
||||
service_name: "{{ item.key }}"
|
||||
sources:
|
||||
- "{{ role_path }}/templates/grafana.ini.j2"
|
||||
- "{{ node_custom_config }}/{{ item }}.ini"
|
||||
- "{{ node_custom_config }}/grafana/{{ inventory_hostname }}/{{ item }}.ini"
|
||||
- "{{ node_custom_config }}/{{ item.key }}.ini"
|
||||
- "{{ node_custom_config }}/grafana/{{ inventory_hostname }}/{{ item.key }}.ini"
|
||||
dest: "{{ node_config_directory }}/grafana/grafana.ini"
|
||||
with_items:
|
||||
- "grafana"
|
||||
register: grafana_confs
|
||||
when:
|
||||
- inventory_hostname in groups[item.value.group]
|
||||
- item.value.enabled | bool
|
||||
with_dict: "{{ grafana_services }}"
|
||||
notify:
|
||||
- Restart grafana container
|
||||
|
||||
- name: Check grafana 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_grafana_containers
|
||||
when:
|
||||
- action != "config"
|
||||
- inventory_hostname in groups[item.value.group]
|
||||
- item.value.enabled | bool
|
||||
with_dict: "{{ grafana_services }}"
|
||||
notify:
|
||||
- Restart grafana container
|
||||
|
@ -5,5 +5,5 @@
|
||||
- include: bootstrap.yml
|
||||
when: inventory_hostname in groups['grafana']
|
||||
|
||||
- include: start.yml
|
||||
when: inventory_hostname in groups['grafana']
|
||||
- name: Flush handlers
|
||||
meta: flush_handlers
|
||||
|
@ -1,47 +1,2 @@
|
||||
---
|
||||
- name: Ensuring the containers up
|
||||
kolla_docker:
|
||||
name: "grafana"
|
||||
action: "get_container_state"
|
||||
register: container_state
|
||||
failed_when: container_state.Running == false
|
||||
when: inventory_hostname in groups['grafana']
|
||||
|
||||
- include: config.yml
|
||||
|
||||
- name: Check the configs
|
||||
command: docker exec grafana /usr/local/bin/kolla_set_configs --check
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
register: check_results
|
||||
when: inventory_hostname in groups['grafana']
|
||||
|
||||
# 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: "grafana"
|
||||
action: "get_container_env"
|
||||
register: container_envs
|
||||
when: inventory_hostname in groups['grafana']
|
||||
|
||||
- name: Remove the containers
|
||||
kolla_docker:
|
||||
name: "grafana"
|
||||
action: "remove_container"
|
||||
register: remove_containers
|
||||
when:
|
||||
- config_strategy == "COPY_ONCE"
|
||||
- inventory_hostname in groups['grafana']
|
||||
|
||||
- include: start.yml
|
||||
when: remove_containers.changed
|
||||
|
||||
- name: Restart containers
|
||||
kolla_docker:
|
||||
name: "grafana"
|
||||
action: "restart_container"
|
||||
when:
|
||||
- config_strategy == 'COPY_ALWAYS'
|
||||
- inventory_hostname in groups['grafana']
|
||||
- include: deploy.yml
|
||||
|
@ -1,13 +0,0 @@
|
||||
---
|
||||
- name: Starting grafana container
|
||||
kolla_docker:
|
||||
action: "start_container"
|
||||
common_options: "{{ docker_common_options }}"
|
||||
image: "{{ grafana_image_full }}"
|
||||
name: "grafana"
|
||||
volumes:
|
||||
- "{{ node_config_directory }}/grafana/:{{ container_config_directory }}/:ro"
|
||||
- "/etc/localtime:/etc/localtime:ro"
|
||||
- "grafana:/var/lib/grafana/"
|
||||
- "kolla_logs:/var/log/kolla/"
|
||||
when: inventory_hostname in groups['grafana']
|
@ -1,4 +1,5 @@
|
||||
---
|
||||
- include: config.yml
|
||||
|
||||
- include: start.yml
|
||||
- name: Flush handlers
|
||||
meta: flush_handlers
|
||||
|
Loading…
Reference in New Issue
Block a user