summaryrefslogtreecommitdiff
path: root/roles/monitoring/grafana/tasks/main.yml
blob: 46130882240931823708175fab07bbf9e866f781 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
---
- name: add debian repository
  include_role:
    name: apt-repo/grafana

- name: install apt packages
  apt:
    name: grafana
    state: present

- name: configure grafana server
  loop: "{{ grafana_config_server | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  ini_file:
    path: /etc/grafana/grafana.ini
    section: server
    option: "{{ item.key }}"
    value: "{{ item.value | string }}"
  notify: restart grafana

- name: configure grafana analytics
  loop: "{{ grafana_config_analytics | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  ini_file:
    path: /etc/grafana/grafana.ini
    section: analytics
    option: "{{ item.key }}"
    value: "{{ item.value | string }}"
  notify: restart grafana

- name: configure grafana security
  loop: "{{ grafana_config_security | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  ini_file:
    path: /etc/grafana/grafana.ini
    section: security
    option: "{{ item.key }}"
    value: "{{ item.value | string }}"
  notify: restart grafana

- name: configure grafana users
  loop: "{{ grafana_config_users | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  ini_file:
    path: /etc/grafana/grafana.ini
    section: users
    option: "{{ item.key }}"
    value: "{{ item.value | string }}"
  notify: restart grafana


- name: install datasources
  copy:
    dest: "/etc/grafana/provisioning/datasources/ansible.yml"
    content: |
      apiVersion: 1
      deleteDatasources: []
      {{ {'datasources': grafana_datasources} | to_nice_yaml(indent=2) }}
    group: grafana
    mode: 0640
  notify: restart grafana

- name: install datasources
  copy:
    dest: "/etc/grafana/provisioning/dashboards/ansible.yml"
    content: |
      apiVersion: 1
      providers:
      - name: ansible'
        folder: ''
        options:
          path: /var/lib/grafana/dashboards/ansible
          foldersFromFilesStructure: true
    group: grafana
    mode: 0644
  notify: restart grafana

- name: create directory for dashboards
  file:
    path: /var/lib/grafana/dashboards/ansible
    state: directory
    group: grafana
    mode: 0750

  ## TODO: fix datasource selection
- name: install
  loop: "{{ grafana_dashboards }}"
  copy:
    src: "dashboard-{{ item }}.json"
    dest: "/var/lib/grafana/dashboards/ansible/{{ item }}.json"

- name: make sure grafan-server is enabled and started
  systemd:
    name: grafana-server
    state: started
    enabled: yes