ceph-ansible/roles/ceph-grafana/tasks/configure_grafana.yml

112 lines
3.3 KiB
YAML
Raw Normal View History

---
- name: install ceph-grafana-dashboards package on RedHat or SUSE
package:
name: ceph-grafana-dashboards
state: "{{ (upgrade_ceph_packages|bool) | ternary('latest','present') }}"
register: result
until: result is succeeded
when:
- not containerized_deployment | bool
- ansible_os_family in ['RedHat', 'Suse']
tags: package-install
- name: make sure grafana is down
service:
name: grafana-server
state: stopped
- name: wait for grafana to be stopped
wait_for:
host: '{{ grafana_server_addr }}'
port: '{{ grafana_port }}'
state: stopped
- name: make sure grafana configuration directories exist
file:
path: "{{ item }}"
state: directory
recurse: yes
owner: "{{ grafana_uid }}"
group: "{{ grafana_uid }}"
with_items:
- "/etc/grafana/dashboards/ceph-dashboard"
- "/etc/grafana/provisioning/datasources"
- "/etc/grafana/provisioning/dashboards"
- "/etc/grafana/provisioning/notifiers"
- name: download ceph grafana dashboards
get_url:
url: "https://raw.githubusercontent.com/ceph/ceph/{{ grafana_dashboard_version }}/monitoring/grafana/dashboards/{{ item }}"
dest: "/etc/grafana/dashboards/ceph-dashboard/{{ item }}"
with_items: "{{ grafana_dashboard_files }}"
when:
- not containerized_deployment | bool
- not ansible_os_family in ['RedHat', 'Suse']
- name: write grafana.ini
template:
src: grafana.ini.j2
dest: /etc/grafana/grafana.ini
owner: "{{ grafana_uid }}"
group: "{{ grafana_uid }}"
mode: 0640
- name: write datasources provisioning config file
template:
src: datasources-ceph-dashboard.yml.j2
dest: /etc/grafana/provisioning/datasources/ceph-dashboard.yml
owner: "{{ grafana_uid }}"
group: "{{ grafana_uid }}"
mode: 0640
- name: Write dashboards provisioning config file
template:
src: dashboards-ceph-dashboard.yml.j2
dest: /etc/grafana/provisioning/dashboards/ceph-dashboard.yml
owner: "{{ grafana_uid }}"
group: "{{ grafana_uid }}"
mode: 0640
when: not containerized_deployment | bool
- name: copy grafana SSL certificate file
copy:
src: "{{ grafana_crt }}"
dest: "/etc/grafana/ceph-dashboard.crt"
owner: "{{ grafana_uid }}"
group: "{{ grafana_uid }}"
mode: 0640
when:
- grafana_crt | bool
- dashboard_protocol == "https"
- name: copy grafana SSL certificate key
copy:
src: "{{ grafana_key }}"
dest: "/etc/grafana/ceph-dashboard.key"
owner: "{{ grafana_uid }}"
group: "{{ grafana_uid }}"
mode: 0440
when:
- grafana_key | bool
- dashboard_protocol == "https"
- name: generate a Self Signed OpenSSL certificate for dashboard
shell: |
test -f /etc/grafana/ceph-dashboard.key -a -f /etc/grafana/ceph-dashboard.crt || \
(openssl req -new -nodes -x509 -subj '/O=IT/CN=ceph-grafana' -days 3650 -keyout /etc/grafana/ceph-dashboard.key -out /etc/grafana/ceph-dashboard.crt -extensions v3_ca && \
chown {{ grafana_uid }}:{{ grafana_uid }} /etc/grafana/ceph-dashboard.key /etc/grafana/ceph-dashboard.crt)
when:
- dashboard_protocol == "https"
- not grafana_key | bool or not grafana_crt | bool
- name: enable and start grafana
service:
name: grafana-server
state: restarted
enabled: true
- name: wait for grafana to start
wait_for:
host: '{{ grafana_server_addr }}'
port: '{{ grafana_port }}'