---
- name: Checking if Grafana container needs upgrading
  vars:
    service_name: "grafana"
    service: "{{ grafana_services[service_name] }}"
  become: true
  kolla_container:
    action: "compare_image"
    common_options: "{{ docker_common_options }}"
    name: "{{ project_name }}"
    image: "{{ grafana_image_full }}"
  when: inventory_hostname in groups['grafana']
  register: grafana_differs

- import_tasks: config.yml

- import_tasks: check-containers.yml

# NOTE(dszumski): We don't want old Grafana instances running after
# a new instance has updated the DB schema. Since the first instance
# is upgraded first, we stop all the other ones.
- name: Stopping all Grafana instances but the first node
  become: true
  kolla_container:
    action: "stop_container"
    common_options: "{{ docker_common_options }}"
    name: "{{ project_name }}"
  when:
    - inventory_hostname != groups['grafana'] | first
    - grafana_differs['result']

- name: Flush handlers
  meta: flush_handlers
