init.sls 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #
  2. # grafana
  3. #
  4. {% set grafana_cfg = salt['pillar.get']('grafana') %}
  5. {% set node_config = salt['pillar.get']('nodes:' ~ grains['id']) %}
  6. {% if node_config.get('role') == "prometheus-server" %}
  7. include:
  8. - .prometheus
  9. {% endif %}
  10. grafana:
  11. # add Grafana Repo
  12. file.managed:
  13. - names:
  14. - /usr/share/keyrings/grafana.key:
  15. - source: salt://grafana/grafana.key
  16. - /etc/apt/sources.list.d/grafana.list:
  17. - source: salt://grafana/grafana.list.tmpl
  18. - template: jinja
  19. - require:
  20. - file: /usr/share/keyrings/grafana.key
  21. # install grafana
  22. pkg.installed:
  23. - name: grafana
  24. - require:
  25. - file: /etc/apt/sources.list.d/grafana.list
  26. service.running:
  27. - name: grafana-server
  28. - enable: True
  29. - require:
  30. - pkg: grafana
  31. - file: /etc/grafana/grafana.ini
  32. - file: /etc/grafana/ldap.toml
  33. - user: grafana
  34. - watch:
  35. - file: /etc/grafana/grafana.ini
  36. - file: /etc/grafana/ldap.toml
  37. # add user 'grafana' to group 'ssl-cert' to access ssl-key file
  38. user.present:
  39. - name: grafana
  40. - system: True
  41. - groups:
  42. - ssl-cert
  43. - require:
  44. - pkg: grafana
  45. /etc/grafana/grafana.ini:
  46. file.managed:
  47. - source: salt://grafana/grafana.ini.tmpl
  48. - template: jinja
  49. config: {{ grafana_cfg }}
  50. - require:
  51. - pkg: grafana
  52. /etc/grafana/ldap.toml:
  53. {% if 'ldap' in grafana_cfg %}
  54. file.managed:
  55. - source: salt://grafana/ldap.toml.tmpl
  56. - template: jinja
  57. config: {{ grafana_cfg.ldap }}
  58. {% else %}
  59. file.absent:
  60. {% endif %}
  61. - require:
  62. - pkg: grafana