aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2019-09-28 21:06:36 -0400
committerMitch Riedstra <mitch@riedstra.us>2019-09-28 21:06:36 -0400
commit377df0b6841bf61f128c8b9098cc1bf6d506a5b7 (patch)
tree789bc2d3dc46cf1da0a4c62b8e6f49b1ad7fb83b
parent4d82dba8e2ce90364cb899a293c75ba37cbb791f (diff)
downloadprometheus-377df0b6841bf61f128c8b9098cc1bf6d506a5b7.tar.gz
prometheus-377df0b6841bf61f128c8b9098cc1bf6d506a5b7.tar.xz
Update the role, add some more documentation, and a license
-rw-r--r--LICENSE20
-rw-r--r--defaults/main.yml19
-rw-r--r--readme.md11
-rw-r--r--tasks/main.yml43
-rw-r--r--tasks/main.yml.bak58
-rw-r--r--tasks/runit.yml17
-rw-r--r--tasks/systemd.yml9
-rw-r--r--templates/prometheus/runit/run9
-rw-r--r--templates/prometheus/systemd.unit5
9 files changed, 84 insertions, 107 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..eaf4522
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2019 Mitchell Riedstra
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/defaults/main.yml b/defaults/main.yml
index 23bdc38..5c9be85 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -1,18 +1,31 @@
---
+# Use this to override the template for more complicated uses
+prometheus_template_source: prometheus/prometheus.yml
+
prometheus_ui_listen: ':9090'
prometheus_home_dir: /var/lib/prometheus
prometheus_data_dir: '{{prometheus_home_dir}}/data'
prometheus_retention_time: "730d"
+prometheus_log: '{{prometheus_home_dir}}/log'
prometheus_user: prometheus
-prometheus_version: "2.7.2"
+prometheus_version: "2.12.0"
prometheus_os: "{{ansible_facts['system']|lower}}" # Should resolve to "linux"
-prometheus_checksum: fca1b17bef8bd19c2ad90caf13d7ffa85e8c4655aa03315fb5e228bd06c4e0ae
+prometheus_checksum: b9f57b6e64fb3048742cfa7dbcc727e1df906d8020ef246a5e81b7959ae97e08
prometheus_architecture: amd64
-# https://github.com/prometheus/prometheus/releases/download/v2.7.2/prometheus-2.7.2.linux-amd64.tar.gz
prometheus_url: "https://github.com/prometheus/prometheus/releases/download/v{{prometheus_version}}/prometheus-{{prometheus_version}}.{{prometheus_os}}-{{prometheus_architecture}}.tar.gz"
+# Newlines are automatically replaced with spaces
+prometheus_opts: |
+ --config.file "{{prometheus_home_dir}}/conf/prometheus.yml"
+ --storage.tsdb.path "{{prometheus_data_dir}}"
+ --storage.tsdb.retention.time "{{prometheus_retention_time}}"
+ --web.listen-address "{{prometheus_ui_listen}}"
+ --web.enable-admin-api
+
+
+# The default template makes it easy to scrape Netdata from internal hosts
prometheus_netdata_hosts:
- localhost:19999
diff --git a/readme.md b/readme.md
index 8de3e32..f563577 100644
--- a/readme.md
+++ b/readme.md
@@ -1,6 +1,13 @@
-# Prometheus role for Void Linux and Ubuntu
+# Prometheus role for Alpine, Void Linux, Ubuntu, and CentOS
-Depends on my netdata role as well as my Nginx role available from:
+You can easily override the default Prometheus template with
+`prometheus_template_source: production/prometheus.yml` in your `group_vars` or
+so.
+
+Updating and or changing versions of Prometheus is as simple as changing
+the version and checksum in your vars.
+
+Works well with my Netdata role which is available here:
https://git.riedstra.us/ansible
diff --git a/tasks/main.yml b/tasks/main.yml
index 10648a0..3f2c2a4 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -27,7 +27,7 @@
- name: Extract Prometheus
shell: |
if ! [ -e "{{prometheus_home_dir}}/{{prometheus_extract_dir}}" ] ; then
- sudo su - '{{prometheus_user}}' -c 'tar xzf prometheus-{{prometheus_version}}.tgz'
+ su - '{{prometheus_user}}' -c 'tar xzf prometheus-{{prometheus_version}}.tgz'
fi
changed_when: false
- name: Link prometheus directory
@@ -46,40 +46,13 @@
- prometheus.yml
- name: Write prometheus template
template:
- src: prometheus/prometheus.yml
+ src: '{{prometheus_template_source}}'
dest: '{{prometheus_home_dir}}/conf/prometheus.yml'
owner: '{{prometheus_user}}'
mode: '0600'
-- name: Write Systemd Unite
- template:
- src: prometheus/systemd.unit
- dest: /etc/systemd/system/prometheus.service
- when: ansible_facts['distribution'].lower() == "ubuntu"
-- name: 'Enable Prometheus [Ubuntu]'
- systemd:
- enabled: yes
- daemon_reload: yes
- name: prometheus
- when: ansible_facts['distribution'].lower() == "ubuntu"
-- name: Create Runit Directory
- file:
- state: directory
- dest: /etc/sv.local/prometheus
- owner: root
- group: adm
- mode: '0755'
- when: ansible_facts['distribution'].lower() == "void"
-- name: Write runit service
- template:
- src: prometheus/runit/run
- dest: /etc/sv.local/prometheus/run
- owner: root
- group: adm
- mode: '0755'
- when: ansible_facts['distribution'].lower() == "void"
-- name: Enable Runit service
- file:
- state: link
- src: /etc/sv.local/prometheus
- dest: /var/service/prometheus
- when: ansible_facts['distribution'].lower() == "void"
+- name: Run Runit Specific tasks
+ include_tasks: systemd.yml
+ when: ansible_facts['distribution'].lower() == "ubuntu" or ansible_facts['distribution'].lower() == "centos"
+- name: Run Runit Specific tasks
+ include_tasks: runit.yml
+ when: ansible_facts['distribution'].lower() == "void" or ansible_facts['distribution'].lower() == "alpine"
diff --git a/tasks/main.yml.bak b/tasks/main.yml.bak
deleted file mode 100644
index 587dfc5..0000000
--- a/tasks/main.yml.bak
+++ /dev/null
@@ -1,58 +0,0 @@
-- name: Setup Prometheus User
- user:
- name: "{{prometheus_user}}"
- home: "{{prometheus_home_dir}}"
- state: present
-- name: Get User home directory
- shell: "awk -F: '{if($1==\"{{prometheus_user}}\"){print $6}}' /etc/passwd"
- changed_when: false
- register: get_home_command_output
-- set_fact: "prometheus_user_home={{get_home_command_output['stdout']}}"
-- set_fact: "prometheus_dir=prometheus-{{prometheus_version}}.{{prometheus_os}}-{{prometheus_architecture}}"
-- name: Create configuration directory
- file:
- state: directory
- dest: "{{prometheus_user_home}}/conf"
- mode: '0700'
- owner: "{{prometheus_user}}"
-- name: Create Data directory
- file:
- state: directory
- dest: "{{prometheus_data_dir}}"
- mode: '0700'
- owner: "{{prometheus_user}}"
-- name: Download Prometheus
- get_url:
- url: "{{prometheus_url}}"
- dest: "{{prometheus_user_home}}/prometheus-{{prometheus_version}}.tgz"
- mode: '0600'
- owner: "{{prometheus_user}}"
-# There's a bug in become_user that doesn't set permissions on the temp directory
-# which is asinine when my user has sudo persmissions.
-- name: Extract Prometheus
- shell: |
- if ! [ -e "{{prometheus_user_home}}/{{prometheus_dir}}" ] ; then
- sudo su - '{{prometheus_user}}' -c 'tar xzf prometheus-{{prometheus_version}}.tgz'
- fi
- changed_when: false
-- name: Link prometheus directory
- file:
- state: link
- src: '{{prometheus_dir}}'
- dest: '{{prometheus_user_home}}/prometheus'
- force: yes
-- name: Link configuration files
- file:
- state: link
- src: '../conf/{{item}}'
- dest: '{{prometheus_user_home}}/prometheus/{{item}}'
- force: yes
- loop:
- - prometheus.yml
-- name: Write prometheus template
- template:
- src: prometheus/prometheus.yml
- dest: '{{prometheus_user_home}}/conf/prometheus.yml'
- owner: '{{prometheus_user}}'
- mode: '0600'
-
diff --git a/tasks/runit.yml b/tasks/runit.yml
new file mode 100644
index 0000000..d8bf8d4
--- /dev/null
+++ b/tasks/runit.yml
@@ -0,0 +1,17 @@
+- name: Create Runit Directory
+ file:
+ state: directory
+ dest: /etc/sv/prometheus
+ owner: root
+ mode: '0755'
+- name: Write runit service
+ template:
+ src: prometheus/runit/run
+ dest: /etc/sv/prometheus/run
+ owner: root
+ mode: '0755'
+- name: Enable Runit service
+ file:
+ state: link
+ src: /etc/sv/prometheus
+ dest: /var/service/prometheus
diff --git a/tasks/systemd.yml b/tasks/systemd.yml
new file mode 100644
index 0000000..031f036
--- /dev/null
+++ b/tasks/systemd.yml
@@ -0,0 +1,9 @@
+- name: Write Systemd Unit
+ template:
+ src: prometheus/systemd.unit
+ dest: /etc/systemd/system/prometheus.service
+- name: 'Enable Prometheus [Systemd]'
+ systemd:
+ enabled: yes
+ daemon_reload: yes
+ name: prometheus
diff --git a/templates/prometheus/runit/run b/templates/prometheus/runit/run
index cf9ad65..b14e2d1 100644
--- a/templates/prometheus/runit/run
+++ b/templates/prometheus/runit/run
@@ -1,6 +1,5 @@
#!/bin/sh
-exec {{prometheus_home_dir}}/prometheus/prometheus \
- --config.file "{{prometheus_home_dir}}/conf/prometheus.yml" \
- --storage.tsdb.path "{{prometheus_data_dir}}" \
- --storage.tsdb.retention.time "{{prometheus_retention_time}}" \
- --web.listen-address "{{prometheus_ui_listen}}"
+exec chpst -u {{prometheus_user}} \
+ {{prometheus_home_dir}}/prometheus/prometheus \
+ {{prometheus_opts | replace('\n', ' ')}} \
+ > {{prometheus_log}} 2>&1
diff --git a/templates/prometheus/systemd.unit b/templates/prometheus/systemd.unit
index 856f299..b1bd6cb 100644
--- a/templates/prometheus/systemd.unit
+++ b/templates/prometheus/systemd.unit
@@ -7,9 +7,6 @@ After=network-online.target
[Service]
User=prometheus
Restart=on-failure
-ExecStart={{prometheus_home_dir}}/prometheus/prometheus \
- --config.file "{{prometheus_home_dir}}/conf/prometheus.yml" \
- --storage.tsdb.path "{{prometheus_data_dir}}" \
- --web.listen-address "{{prometheus_ui_listen}}"
+ExecStart={{prometheus_home_dir}}/prometheus/prometheus {{prometheus_opts | replace('\n', ' ')}}
[Install]
WantedBy=multi-user.target