From 46f2b6c0f6ff7cf096b54bcf37a1b33391266c57 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Thu, 30 Jul 2020 01:10:27 -0400 Subject: [PATCH] Persist Prometheus data in bind mount --- dev/host_vars/dockerbox.yml | 2 +- roles/prometheus/defaults/main.yml | 2 +- roles/prometheus/tasks/main.yml | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dev/host_vars/dockerbox.yml b/dev/host_vars/dockerbox.yml index fa27826..5f5007c 100644 --- a/dev/host_vars/dockerbox.yml +++ b/dev/host_vars/dockerbox.yml @@ -35,4 +35,4 @@ prom_version: latest prom_domain: prom.vm.krislamo.org grafana_version: latest grafana_domain: grafana.vm.krislamo.org -prom_targets: "['127.0.0.1', '127.0.0.1:9100']" +prom_targets: "['10.0.2.15:9100']" diff --git a/roles/prometheus/defaults/main.yml b/roles/prometheus/defaults/main.yml index e39238b..4cb7f9d 100644 --- a/roles/prometheus/defaults/main.yml +++ b/roles/prometheus/defaults/main.yml @@ -1,3 +1,3 @@ prom_name: prometheus grafana_name: grafana -prom_root: "/opt/{{ prom_name }}/config" +prom_root: "/opt/{{ prom_name }}" diff --git a/roles/prometheus/tasks/main.yml b/roles/prometheus/tasks/main.yml index 45cf189..2291140 100644 --- a/roles/prometheus/tasks/main.yml +++ b/roles/prometheus/tasks/main.yml @@ -8,15 +8,21 @@ name: prometheus-node-exporter state: started -- name: Create Prometheus directories +- name: Create Prometheus data directory file: - path: "{{ prom_root }}" + path: "{{ prom_root }}/prometheus" + state: directory + owner: nobody + +- name: Create Prometheus config directory + file: + path: "{{ prom_root }}/config" state: directory - name: Install Prometheus configuration template: src: prometheus.yml.j2 - dest: "{{ prom_root }}/prometheus.yml" + dest: "{{ prom_root }}/config/prometheus.yml" - name: Create Prometheus network docker_network: @@ -28,7 +34,9 @@ image: prom/prometheus:{{ prom_version }} state: started restart_policy: always - volumes: "{{ prom_root }}:/etc/prometheus" + volumes: + - "{{ prom_root }}/config:/etc/prometheus" + - "{{ prom_root }}/prometheus:/prometheus" networks_cli_compatible: true networks: - name: "{{ prom_name }}"