1
0
Fork 0
mirror of https://github.com/mdlayher/homelab.git synced 2024-12-15 17:50:54 +00:00

prometheus: only install different version, unless forced

This commit is contained in:
Matt Layher 2017-08-22 10:47:26 -04:00
parent 446cce3960
commit d8a0df811f
No known key found for this signature in database
GPG key ID: 77BFE531397EDE94
2 changed files with 34 additions and 2 deletions

View file

@ -1,7 +1,21 @@
---
- name: check if installing a different version of prometheus
tags:
- prometheus
shell: "cat {{ prometheus_config }}/.sha256"
ignore_errors: yes
register: checksum
- name: determine if prometheus {{ prometheus_version}} should be installed
tags:
- prometheus
set_fact:
prometheus_install: (checksum.stdout.find(prometheus_sha256) == -1) or (prometheus_force is defined)
- name: download and checksum prometheus {{ prometheus_version }} tarball
tags:
- prometheus
when: prometheus_install
get_url:
url: "{{ prometheus_url }}"
dest: "{{ prometheus_tgz }}"
@ -10,6 +24,7 @@
- name: unpack prometheus tarball
tags:
- prometheus
when: prometheus_install
unarchive:
src: "{{ prometheus_tgz }}"
dest: "/tmp/"
@ -18,6 +33,7 @@
- name: create prometheus user
tags:
- prometheus
when: prometheus_install
user:
name: prometheus
shell: "/bin/false"
@ -28,12 +44,12 @@
- prometheus
stat:
path: "/etc/systemd/system/prometheus.service"
register: checked
register: svccheck
- name: stop prometheus service if it exists
tags:
- prometheus
when: checked.stat.exists
when: svccheck.stat.exists
service:
name: prometheus
state: stopped
@ -41,6 +57,7 @@
- name: copy prometheus binaries to /usr/local/bin
tags:
- prometheus
when: prometheus_install
command: "cp {{ prometheus_tmp }}/{{ item }} /usr/local/bin/"
with_items:
- "prometheus"
@ -49,6 +66,7 @@
- name: set permissions on prometheus binaries
tags:
- prometheus
when: prometheus_install
file:
path: "/usr/local/bin/{{ item }}"
owner: prometheus
@ -61,6 +79,7 @@
- name: create prometheus config directory
tags:
- prometheus
when: prometheus_install
file:
path: "{{ prometheus_config }}"
state: directory
@ -86,6 +105,7 @@
- name: create prometheus data directory
tags:
- prometheus
when: prometheus_install
file:
path: "{{ prometheus_data }}"
state: directory
@ -116,9 +136,18 @@
- name: remove temporary prometheus files
tags:
- prometheus
when: prometheus_install
file:
path: "{{ item }}"
state: absent
with_items:
- "{{ prometheus_tmp }}"
- "{{ prometheus_tgz }}"
- name: create checksum file for prometheus {{ prometheus_version }}
tags:
- prometheus
when: prometheus_install
template:
src: sha256.j2
dest: "{{ prometheus_config }}/.sha256"

View file

@ -0,0 +1,3 @@
# {{ ansible_managed }}
# Remove this file to force ansible to reinstall prometheus {{ prometheus_version }}.
{{ prometheus_sha256 }}