add prometheus role
This commit is contained in:
65
roles/prometheus/tasks/configure.yaml
Normal file
65
roles/prometheus/tasks/configure.yaml
Normal file
@ -0,0 +1,65 @@
|
||||
---
|
||||
- name: create group
|
||||
group:
|
||||
name: "{{ prometheus_group }}"
|
||||
system: true
|
||||
state: "{{ prometheus_group_state | default('present') }}"
|
||||
|
||||
- name: create user
|
||||
user:
|
||||
name: "{{ prometheus_user }}"
|
||||
system: true
|
||||
shell: "{{ prometheus_user_shell }}"
|
||||
group: "{{ prometheus_group }}"
|
||||
createhome: false
|
||||
home: "{{ prometheus_var_path }}"
|
||||
state: "{{ prometheus_user_state | default('present') }}"
|
||||
|
||||
- name: create etc path
|
||||
file:
|
||||
path: "{{ prometheus_etc_path }}"
|
||||
state: directory
|
||||
owner: "{{ prometheus_etc_owner }}"
|
||||
group: "{{ prometheus_etc_group }}"
|
||||
mode: "{{ prometheus_etc_mode }}"
|
||||
|
||||
- name: create var path
|
||||
file:
|
||||
path: "{{ prometheus_var_path }}"
|
||||
state: directory
|
||||
owner: "{{ prometheus_var_owner }}"
|
||||
group: "{{ prometheus_var_group }}"
|
||||
mode: "{{ prometheus_var_mode }}"
|
||||
|
||||
- name: configure
|
||||
copy:
|
||||
dest: "{{ prometheus_etc_path }}/prometheus.yaml"
|
||||
content: "{{ (prometheus_config | default({})) | to_yaml }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0444
|
||||
notify: restart prometheus
|
||||
|
||||
- name: configure rules
|
||||
copy:
|
||||
dest: "{{ prometheus_etc_path }}/rules.yaml"
|
||||
content: "{{ (prometheus_rules_config | default({})) | to_yaml }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0444
|
||||
notify: reload prometheus
|
||||
|
||||
- name: configure systemd template
|
||||
template:
|
||||
src: prometheus.service.j2
|
||||
dest: /etc/systemd/system/prometheus.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0444
|
||||
notify: restart prometheus
|
||||
|
||||
- name: manage service
|
||||
service:
|
||||
name: "{{ prometheus_service_name }}"
|
||||
enabled: "{{ prometheus_service_enabled }}"
|
||||
state: "{{ prometheus_service_state }}"
|
0
roles/prometheus/tasks/default.yaml
Normal file
0
roles/prometheus/tasks/default.yaml
Normal file
32
roles/prometheus/tasks/install.yaml
Normal file
32
roles/prometheus/tasks/install.yaml
Normal file
@ -0,0 +1,32 @@
|
||||
---
|
||||
- block:
|
||||
- name: download tar
|
||||
get_url:
|
||||
url: "{{ prometheus_release_url }}"
|
||||
dest: "{{ prometheus_download_path }}"
|
||||
checksum: "{{ prometheus_checksum }}"
|
||||
register: dl
|
||||
until: dl is success
|
||||
retries: 5
|
||||
delay: 10
|
||||
|
||||
- name: extract tar
|
||||
unarchive:
|
||||
src: "{{ prometheus_download_path }}"
|
||||
dest: "{{ prometheus_unarchive_dest_path }}"
|
||||
creates: "{{ prometheus_extracted_path }}/prometheus"
|
||||
remote_src: true
|
||||
|
||||
- name: install binaries
|
||||
copy:
|
||||
src: "{{ prometheus_extracted_path }}/{{ item }}"
|
||||
dest: "{{ prometheus_bin_path }}/{{ item }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0755
|
||||
remote_src: true
|
||||
loop:
|
||||
- promtool
|
||||
- prometheus
|
||||
notify: restart prometheus
|
||||
when: prometheus_version != prometheus_local_version
|
34
roles/prometheus/tasks/main.yaml
Normal file
34
roles/prometheus/tasks/main.yaml
Normal file
@ -0,0 +1,34 @@
|
||||
---
|
||||
- name: gather os specific variables
|
||||
include_vars: "{{ lookup('first_found', possible_files) }}"
|
||||
vars:
|
||||
possible_files:
|
||||
files:
|
||||
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml"
|
||||
- "{{ ansible_distribution }}.yaml"
|
||||
- "{{ ansible_os_family }}.yaml"
|
||||
- "default.yaml"
|
||||
paths:
|
||||
- vars
|
||||
|
||||
- name: include os specific tasks
|
||||
include_tasks: "{{ lookup('first_found', possible_files) }}"
|
||||
vars:
|
||||
possible_files:
|
||||
files:
|
||||
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml"
|
||||
- "{{ ansible_distribution }}.yaml"
|
||||
- "{{ ansible_os_family }}.yaml"
|
||||
- "default.yaml"
|
||||
paths:
|
||||
- tasks
|
||||
|
||||
- include: pre.yaml
|
||||
|
||||
- include: install.yaml
|
||||
|
||||
- include: configure.yaml
|
||||
notify: restart prometheus
|
||||
|
||||
- include: nginx.yaml
|
||||
when: '"nginx" in ansible_play_role_names'
|
9
roles/prometheus/tasks/nginx.yaml
Normal file
9
roles/prometheus/tasks/nginx.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
- name: configure nginx
|
||||
template:
|
||||
src: nginx.conf.j2
|
||||
dest: "{{ nginx_conf_d_path }}/prometheus.conf"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0444
|
||||
notify: reload nginx
|
50
roles/prometheus/tasks/pre.yaml
Normal file
50
roles/prometheus/tasks/pre.yaml
Normal file
@ -0,0 +1,50 @@
|
||||
---
|
||||
- name: determine if installed
|
||||
stat:
|
||||
path: "{{ prometheus_bin_path }}/prometheus"
|
||||
register: st
|
||||
|
||||
- name: set prometheus_installed
|
||||
set_fact:
|
||||
prometheus_installed: "{{ st.stat.exists | bool }}"
|
||||
|
||||
- block:
|
||||
- name: determine latest version
|
||||
uri:
|
||||
url: https://api.github.com/repos/prometheus/prometheus/releases/latest
|
||||
return_content: true
|
||||
body_format: json
|
||||
register: _latest_version
|
||||
until: _latest_version.status == 200
|
||||
retries: 3
|
||||
|
||||
- name: set prometheus_version
|
||||
set_fact:
|
||||
prometheus_version: "{{ _latest_version.json['tag_name'] | regex_replace('^v', '') }}"
|
||||
|
||||
- block:
|
||||
- name: determine installed version
|
||||
command: "{{ prometheus_bin_path }}/prometheus --version"
|
||||
register: _installed_version_string
|
||||
changed_when: false
|
||||
|
||||
- name: set prometheus_local_version
|
||||
set_fact:
|
||||
prometheus_local_version: "{{ _installed_version_string.stdout | regex_search(prometheus_version_regex, '\\1') | first }}"
|
||||
when: prometheus_installed
|
||||
|
||||
- name: set prometheus_local_version to 0
|
||||
set_fact:
|
||||
prometheus_local_version: "0"
|
||||
when: not prometheus_installed
|
||||
|
||||
- block:
|
||||
- name: get checksums
|
||||
set_fact:
|
||||
_checksums: "{{ lookup('url', prometheus_checksum_url, wantlist=True) }}"
|
||||
|
||||
- name: set prometheus_checksum
|
||||
set_fact:
|
||||
prometheus_checksum: "sha256:{{ item.split(' ') | first }}"
|
||||
loop: "{{ _checksums }}"
|
||||
when: "prometheus_release_file in item"
|
Reference in New Issue
Block a user