rice/docker-host/roles/setup/tasks/prometheus.yml

64 lines
1.7 KiB
YAML

---
- hosts: leftcoastlab
vars:
PROM_URL: "https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz"
become: yes
tasks:
- name: Include Global Vars
include_vars:
dir: ../vars
- name: Download prometheus Node Explorer static binary tarball
get_url:
url: "{{ PROM_URL }}"
dest: /tmp/prom-node-exporer.tar.gz
- name: Untar node exporter tarball package
unarchive:
src: /tmp/prom-node-exporer.tar.gz
dest: /opt/prom-node-exporter
creates: /opt/prom-node-exporter
remote_src: yes
- name: Copy Unit file for node exporter
copy:
src: ../files/services/node_exporter.service
dest: /etc/systemd/system/node_exporter.service
- name: Install Node Exporter Service and Start
systemd:
daemon_reload: yes
name: node_exporter
state: restarted
enabled: yes
- name: Ensure Prom Docker Volume Exists
community.docker.docker_volume:
name: prometheus-volume
- name: Ensure Config directory exists
file:
path: /opt/prometheus
state: directory
- name: Copy Prometheus template to target directory
template:
dest: /opt/prometheus/prometheus.yml
src: ../templates/prometheus.yml.j2
- name: Setup Prometheus (Containerized) Service
community.docker.docker_container:
name: prometheus
image: prom/prometheus
pull: yes
restart_policy: always
recreate: yes
volumes:
- "prometheus-volume:/prometheus"
- "/opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml"
ports:
- "{{PROM_PORT}}:{{PROM_PORT}}"