From c7fba8107afa5e7c657132b26034a7274eaefbcc Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 31 Jan 2021 16:52:24 +0000 Subject: [PATCH] Move grafana to `forrest` --- ansible/host_vars/forrest.yml | 1 + ansible/host_vars/pve-docker.yml | 1 + ansible/main.yml | 5 +- ansible/roles/forrest/handlers/main.yml | 11 ++++ ansible/roles/forrest/tasks/main.yml | 65 +++++++++++++++++++ .../roles/grafana/files/docker-compose.yml | 43 ------------ ansible/roles/grafana/handlers/main.yml | 4 -- ansible/roles/grafana/tasks/main.yml | 21 ------ ansible/roles/traefik/defaults/main.yml | 1 + .../traefik/files/file-provider-grafana.yml | 12 ++++ ansible/roles/traefik/tasks/main.yml | 10 +++ 11 files changed, 105 insertions(+), 69 deletions(-) create mode 100644 ansible/host_vars/forrest.yml create mode 100644 ansible/roles/forrest/handlers/main.yml create mode 100644 ansible/roles/forrest/tasks/main.yml delete mode 100644 ansible/roles/grafana/files/docker-compose.yml delete mode 100644 ansible/roles/grafana/handlers/main.yml delete mode 100644 ansible/roles/grafana/tasks/main.yml create mode 100644 ansible/roles/traefik/files/file-provider-grafana.yml diff --git a/ansible/host_vars/forrest.yml b/ansible/host_vars/forrest.yml new file mode 100644 index 0000000..c6a60bc --- /dev/null +++ b/ansible/host_vars/forrest.yml @@ -0,0 +1 @@ +expose_ssh: true diff --git a/ansible/host_vars/pve-docker.yml b/ansible/host_vars/pve-docker.yml index c12b6c7..b8a9add 100644 --- a/ansible/host_vars/pve-docker.yml +++ b/ansible/host_vars/pve-docker.yml @@ -5,3 +5,4 @@ protected_ip: "{{ pve_hosts.pve_docker.internal_ip }}" traefik_provider_jellyfin: true traefik_provider_homeassistant: true +traefik_provider_grafana: true diff --git a/ansible/main.yml b/ansible/main.yml index f562f4d..5770d0b 100644 --- a/ansible/main.yml +++ b/ansible/main.yml @@ -40,7 +40,6 @@ - hosts: pve-docker roles: - pve_docker - - grafana - gitea - duplicati - yourls @@ -60,3 +59,7 @@ - pve - zfs - pve_nebula_route + +- hosts: forrest + roles: + - forrest diff --git a/ansible/roles/forrest/handlers/main.yml b/ansible/roles/forrest/handlers/main.yml new file mode 100644 index 0000000..46c92bb --- /dev/null +++ b/ansible/roles/forrest/handlers/main.yml @@ -0,0 +1,11 @@ +- name: restart grafana + service: + name: grafana-server + state: restarted + become: true + +- name: restart influxdb + service: + name: influxdb + state: restarted + become: true diff --git a/ansible/roles/forrest/tasks/main.yml b/ansible/roles/forrest/tasks/main.yml new file mode 100644 index 0000000..1238fef --- /dev/null +++ b/ansible/roles/forrest/tasks/main.yml @@ -0,0 +1,65 @@ +- name: Add grafana repository + apt_repository: + repo: deb https://packages.grafana.com/oss/deb stable main + state: present + filename: grafana + +- name: Add influxdb repository + apt_repository: + repo: deb https://repos.influxdata.com/debian buster stable + state: present + filename: influxdb + +- name: Install grafana + package: + name: grafana + become: true + +- name: Install influxdb + package: + name: grafana + become: true + loop: + - influxdb + - chronograf + +- name: Enable grafana + service: + name: grafana-service + enabled: true + become: true + +- name: Enable influxdb + service: + name: influxdb + enabled: true + become: true + +- name: Configure influxdb + ini_file: + path: /etc/influxdb/influxdb.conf + mode: "0644" + section: "{{ item.section }}" + option: "{{ item.option }}" + value: "{{ item.value }}" + become: true + notify: restart influxdb + loop_control: + label: "{{ item.section }}.{{ item.option }}={{ item.value }}" + loop: + - {section: http, option: bind-address, value: ":8086"} + - {section: http, option: auth-enabled, value: "true"} + +- name: Configure grafana + ini_file: + path: /etc/grafana/grafana.ini + mode: "0644" + section: "{{ item.section }}" + option: "{{ item.option }}" + value: "{{ item.value }}" + become: true + notify: restart grafana + loop_control: + label: "{{ item.section }}.{{ item.option }}={{ item.value }}" + loop: + - {section: server, option: domain, value: grafana.jakehoward.tech} diff --git a/ansible/roles/grafana/files/docker-compose.yml b/ansible/roles/grafana/files/docker-compose.yml deleted file mode 100644 index 2802f2a..0000000 --- a/ansible/roles/grafana/files/docker-compose.yml +++ /dev/null @@ -1,43 +0,0 @@ -version: "2.3" - -services: - grafana: - image: grafana/grafana:latest - environment: - - TZ=Europe/London - - GF_DATABASE_URL=postgres://grafana:grafana@db/grafana - - GF_RENDERING_SERVER_URL=http://renderer:8081/render - - GF_RENDERING_CALLBACK_URL=http://grafana:3000/ - volumes: - - ./grafana:/var/lib/grafana - restart: unless-stopped - depends_on: - - db - - renderer - networks: - - default - - grafana - labels: - - traefik.enable=true - - traefik.http.routers.grafana.rule=Host(`grafana.jakehoward.tech`) - - traefik.http.routers.grafana.tls.certresolver=le - - traefik.http.routers.grafana.middlewares=compress@file - - db: - image: postgres:12-alpine - restart: unless-stopped - volumes: - - ./postgres:/var/lib/postgresql/data - environment: - - POSTGRES_PASSWORD=grafana - - POSTGRES_USER=grafana - - renderer: - image: grafana/grafana-image-renderer:latest - restart: unless-stopped - environment: - - BROWSER_TZ=Europe/London - -networks: - grafana: - external: true diff --git a/ansible/roles/grafana/handlers/main.yml b/ansible/roles/grafana/handlers/main.yml deleted file mode 100644 index 92aa72c..0000000 --- a/ansible/roles/grafana/handlers/main.yml +++ /dev/null @@ -1,4 +0,0 @@ -- name: restart grafana - shell: - chdir: /opt/grafana - cmd: "{{ docker_update_command }}" diff --git a/ansible/roles/grafana/tasks/main.yml b/ansible/roles/grafana/tasks/main.yml deleted file mode 100644 index 2847fa7..0000000 --- a/ansible/roles/grafana/tasks/main.yml +++ /dev/null @@ -1,21 +0,0 @@ -- name: Create install directory - file: - path: /opt/grafana - state: directory - owner: "{{ docker_user.name }}" - mode: "{{ docker_compose_directory_mask }}" - become: true - -- name: Create grafana network - docker_network: - name: grafana - -- name: Install compose file - template: - src: files/docker-compose.yml - dest: /opt/grafana/docker-compose.yml - mode: "{{ docker_compose_file_mask }}" - owner: "{{ docker_user.name }}" - validate: /usr/bin/docker-compose -f %s config - notify: restart grafana - become: true diff --git a/ansible/roles/traefik/defaults/main.yml b/ansible/roles/traefik/defaults/main.yml index 0861f0f..355d11a 100644 --- a/ansible/roles/traefik/defaults/main.yml +++ b/ansible/roles/traefik/defaults/main.yml @@ -2,5 +2,6 @@ traefik_influx_db_dir: ./influxdb traefik_provider_jellyfin: false traefik_provider_homeassistant: false +traefik_provider_grafana: false with_traefik_pages: false diff --git a/ansible/roles/traefik/files/file-provider-grafana.yml b/ansible/roles/traefik/files/file-provider-grafana.yml new file mode 100644 index 0000000..9abd82b --- /dev/null +++ b/ansible/roles/traefik/files/file-provider-grafana.yml @@ -0,0 +1,12 @@ +http: + routers: + router-grafana: + rule: Host(`grafana.jakehoward.tech`) + service: service-grafana + tls: + certResolver: le + services: + service-grafana: + loadBalancer: + servers: + - url: http://{{ pve_hosts.forrest.internal_ip }}:3000 diff --git a/ansible/roles/traefik/tasks/main.yml b/ansible/roles/traefik/tasks/main.yml index 9d4ac91..ef7936d 100644 --- a/ansible/roles/traefik/tasks/main.yml +++ b/ansible/roles/traefik/tasks/main.yml @@ -67,3 +67,13 @@ notify: restart traefik when: traefik_provider_jellyfin become: true + +- name: Install grafana provider + template: + src: files/file-provider-grafana.yml + dest: /opt/traefik/traefik/conf/grafana.yml + mode: "{{ docker_compose_file_mask }}" + owner: "{{ docker_user.name }}" + notify: restart traefik + when: traefik_provider_grafana + become: true