---
- name: install gpg so we can import a key
  yum: pkg=gpg state=present
  tags:
  - grafana
  - packages

- name: import gpg key
  rpm_key: state=present key=https://packagecloud.io/gpg.key

- name: import second gpg key
  rpm_key: state=present key=https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana

- name: add repo
  action: copy src=grafana.repo dest=/etc/yum.repos.d/grafana.repo
  tags:
  - grafana
  - packages
  - repo

- name: install grafana
  yum: pkg=grafana state=present
  tags:
  - grafana
  - packages

- name: set sebool so apache can talk to grafana-server
  action: seboolean name=httpd_can_network_connect
                    state=true
                    persistent=true

- name: Set grafana-server to run on boot
  service: name=grafana-server enabled=yes state=running
  tags:
  - service
  - grafana

- name: grafana apache proxy config file
  copy: src=grafana.conf dest=/etc/httpd/conf.d/grafana.conf owner=root group=root mode=644
  notify:
  - restart apache
  tags:
  - grafana
  - config

- name: Install custom systemd service file
  copy: >
    src=grafana.service
    dest=/usr/lib/systemd/system/grafana-server.service
  tags:
  - config
  - grafana
  notify:
  - restart grafana
