Optimize reconfiguration for grafana

Change-Id: I672d6fea935cbe7416ebd0cfff5006fddb9cd534
Partially-implements: blueprint better-reconfigure
This commit is contained in:
Mauricio Lima
2017-01-23 11:40:29 -03:00
parent 5740f11901
commit 43813b8a6d
7 changed files with 78 additions and 74 deletions

View File

@@ -1,6 +1,18 @@
--- ---
project_name: "grafana" 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 # Database
#################### ####################

View 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

View File

@@ -1,27 +1,55 @@
--- ---
- 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:
- "grafana" - inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ grafana_services }}"
- name: Copying over config.json files - name: Copying over config.json files
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: grafana_config_jsons
- "grafana" 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 - name: Copying over grafana.ini
merge_configs: merge_configs:
vars: vars:
service_name: "{{ item }}" service_name: "{{ item.key }}"
sources: sources:
- "{{ role_path }}/templates/grafana.ini.j2" - "{{ role_path }}/templates/grafana.ini.j2"
- "{{ node_custom_config }}/{{ item }}.ini" - "{{ node_custom_config }}/{{ item.key }}.ini"
- "{{ node_custom_config }}/grafana/{{ inventory_hostname }}/{{ item }}.ini" - "{{ node_custom_config }}/grafana/{{ inventory_hostname }}/{{ item.key }}.ini"
dest: "{{ node_config_directory }}/grafana/grafana.ini" dest: "{{ node_config_directory }}/grafana/grafana.ini"
with_items: register: grafana_confs
- "grafana" 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

View File

@@ -5,5 +5,5 @@
- include: bootstrap.yml - include: bootstrap.yml
when: inventory_hostname in groups['grafana'] when: inventory_hostname in groups['grafana']
- include: start.yml - name: Flush handlers
when: inventory_hostname in groups['grafana'] meta: flush_handlers

View File

@@ -1,47 +1,2 @@
--- ---
- name: Ensuring the containers up - include: deploy.yml
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']

View File

@@ -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']

View File

@@ -1,4 +1,5 @@
--- ---
- include: config.yml - include: config.yml
- include: start.yml - name: Flush handlers
meta: flush_handlers