add pushgateway role
This commit is contained in:
parent
749934f9e1
commit
eae4e0120c
42
roles/pushgateway/defaults/main.yaml
Normal file
42
roles/pushgateway/defaults/main.yaml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
---
|
||||||
|
pushgateway_go_arch_map:
|
||||||
|
i386: '386'
|
||||||
|
x86_64: 'amd64'
|
||||||
|
|
||||||
|
pushgateway_go_arch: "{{ pushgateway_go_arch_map[ansible_architecture] | default('amd64') }}"
|
||||||
|
|
||||||
|
pushgateway_service_name: pushgateway.service
|
||||||
|
pushgateway_service_enabled: true
|
||||||
|
pushgateway_service_state: started
|
||||||
|
|
||||||
|
pushgateway_version_regex: ^pushgateway, version ([\d.]+)
|
||||||
|
|
||||||
|
pushgateway_github_project_url: https://github.com/prometheus/pushgateway
|
||||||
|
pushgateway_release_file: "pushgateway-{{ pushgateway_version }}.{{ ansible_system | lower }}-{{ pushgateway_go_arch }}.tar.gz"
|
||||||
|
pushgateway_release_url: "{{ pushgateway_github_project_url }}/releases/download/v{{ pushgateway_version }}/{{ pushgateway_release_file }}"
|
||||||
|
pushgateway_checksum_url: "{{ pushgateway_github_project_url }}/releases/download/v{{ pushgateway_version }}/sha256sums.txt"
|
||||||
|
pushgateway_download_path: "/tmp/{{ pushgateway_release_file }}"
|
||||||
|
pushgateway_unarchive_dest_path: /tmp
|
||||||
|
pushgateway_extracted_path: "{{ pushgateway_download_path | replace('.tar.gz', '') }}"
|
||||||
|
|
||||||
|
pushgateway_user: pushgateway
|
||||||
|
pushgateway_user_state: present
|
||||||
|
pushgateway_user_shell: /usr/sbin/nologin
|
||||||
|
|
||||||
|
pushgateway_group: pushgateway
|
||||||
|
pushgateway_group_state: "{{ pushgateway_user_state | default('present') }}"
|
||||||
|
|
||||||
|
pushgateway_etc_path: /etc/pushgateway
|
||||||
|
pushgateway_etc_owner: root
|
||||||
|
pushgateway_etc_group: root
|
||||||
|
pushgateway_etc_mode: "0755"
|
||||||
|
|
||||||
|
pushgateway_var_path: /var/lib/pushgateway
|
||||||
|
pushgateway_var_owner: "{{ pushgateway_user }}"
|
||||||
|
pushgateway_var_group: "{{ pushgateway_group }}"
|
||||||
|
pushgateway_var_mode: "0755"
|
||||||
|
|
||||||
|
pushgateway_bin_path: /usr/local/bin
|
||||||
|
|
||||||
|
pushgateway_web_listen_address: 0.0.0.0:9091
|
||||||
|
pushgateway_port: "{{ pushgateway_web_listen_address.split(':')[1] }}"
|
11
roles/pushgateway/handlers/main.yaml
Normal file
11
roles/pushgateway/handlers/main.yaml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
- name: restart pushgateway
|
||||||
|
systemd:
|
||||||
|
name: pushgateway.service
|
||||||
|
daemon_reload: true
|
||||||
|
state: restarted
|
||||||
|
|
||||||
|
- name: reload pushgateway
|
||||||
|
service:
|
||||||
|
name: pushgateway.service
|
||||||
|
state: reloaded
|
47
roles/pushgateway/tasks/configure.yaml
Normal file
47
roles/pushgateway/tasks/configure.yaml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
---
|
||||||
|
- name: create group
|
||||||
|
group:
|
||||||
|
name: "{{ pushgateway_group }}"
|
||||||
|
system: true
|
||||||
|
state: "{{ pushgateway_group_state | default('present') }}"
|
||||||
|
|
||||||
|
- name: create user
|
||||||
|
user:
|
||||||
|
name: "{{ pushgateway_user }}"
|
||||||
|
system: true
|
||||||
|
shell: "{{ pushgateway_user_shell }}"
|
||||||
|
group: "{{ pushgateway_group }}"
|
||||||
|
createhome: false
|
||||||
|
home: "{{ pushgateway_var_path }}"
|
||||||
|
state: "{{ pushgateway_user_state | default('present') }}"
|
||||||
|
|
||||||
|
- name: create etc path
|
||||||
|
file:
|
||||||
|
path: "{{ pushgateway_etc_path }}"
|
||||||
|
state: directory
|
||||||
|
owner: "{{ pushgateway_etc_owner }}"
|
||||||
|
group: "{{ pushgateway_etc_group }}"
|
||||||
|
mode: "{{ pushgateway_etc_mode }}"
|
||||||
|
|
||||||
|
- name: create var path
|
||||||
|
file:
|
||||||
|
path: "{{ pushgateway_var_path }}"
|
||||||
|
state: directory
|
||||||
|
owner: "{{ pushgateway_var_owner }}"
|
||||||
|
group: "{{ pushgateway_var_group }}"
|
||||||
|
mode: "{{ pushgateway_var_mode }}"
|
||||||
|
|
||||||
|
- name: configure systemd template
|
||||||
|
template:
|
||||||
|
src: pushgateway.service.j2
|
||||||
|
dest: /etc/systemd/system/pushgateway.service
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0444
|
||||||
|
notify: restart pushgateway
|
||||||
|
|
||||||
|
- name: manage service
|
||||||
|
service:
|
||||||
|
name: "{{ pushgateway_service_name }}"
|
||||||
|
enabled: "{{ pushgateway_service_enabled }}"
|
||||||
|
state: "{{ pushgateway_service_state }}"
|
0
roles/pushgateway/tasks/default.yaml
Normal file
0
roles/pushgateway/tasks/default.yaml
Normal file
31
roles/pushgateway/tasks/install.yaml
Normal file
31
roles/pushgateway/tasks/install.yaml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
- block:
|
||||||
|
- name: download archive
|
||||||
|
get_url:
|
||||||
|
url: "{{ pushgateway_release_url }}"
|
||||||
|
dest: "{{ pushgateway_download_path }}"
|
||||||
|
checksum: "{{ pushgateway_checksum }}"
|
||||||
|
register: dl
|
||||||
|
until: dl is success
|
||||||
|
retries: 5
|
||||||
|
delay: 10
|
||||||
|
|
||||||
|
- name: extract archive
|
||||||
|
unarchive:
|
||||||
|
src: "{{ pushgateway_download_path }}"
|
||||||
|
dest: "{{ pushgateway_unarchive_dest_path }}"
|
||||||
|
creates: "{{ pushgateway_extracted_path }}/pushgateway"
|
||||||
|
remote_src: true
|
||||||
|
|
||||||
|
- name: install binaries
|
||||||
|
copy:
|
||||||
|
src: "{{ pushgateway_extracted_path }}/{{ item }}"
|
||||||
|
dest: "{{ pushgateway_bin_path }}/{{ item }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0755
|
||||||
|
remote_src: true
|
||||||
|
loop:
|
||||||
|
- pushgateway
|
||||||
|
notify: restart pushgateway
|
||||||
|
when: pushgateway_version != pushgateway_local_version
|
33
roles/pushgateway/tasks/main.yaml
Normal file
33
roles/pushgateway/tasks/main.yaml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
---
|
||||||
|
- 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
|
||||||
|
|
||||||
|
#- include: nginx.yaml
|
||||||
|
# when: '"nginx" in ansible_play_role_names'
|
50
roles/pushgateway/tasks/pre.yaml
Normal file
50
roles/pushgateway/tasks/pre.yaml
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
---
|
||||||
|
- name: determine if installed
|
||||||
|
stat:
|
||||||
|
path: "{{ pushgateway_bin_path }}/pushgateway"
|
||||||
|
register: st
|
||||||
|
|
||||||
|
- name: set pushgateway_installed
|
||||||
|
set_fact:
|
||||||
|
pushgateway_installed: "{{ st.stat.exists | bool }}"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: determine latest version
|
||||||
|
uri:
|
||||||
|
url: https://api.github.com/repos/prometheus/pushgateway/releases/latest
|
||||||
|
return_content: true
|
||||||
|
body_format: json
|
||||||
|
register: _latest_version
|
||||||
|
until: _latest_version.status == 200
|
||||||
|
retries: 3
|
||||||
|
|
||||||
|
- name: set pushgateway_version
|
||||||
|
set_fact:
|
||||||
|
pushgateway_version: "{{ _latest_version.json['tag_name'] | regex_replace('^v', '') }}"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: determine installed version
|
||||||
|
command: "{{ pushgateway_bin_path }}/pushgateway --version"
|
||||||
|
register: _installed_version_string
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: set pushgateway_local_version
|
||||||
|
set_fact:
|
||||||
|
pushgateway_local_version: "{{ _installed_version_string.stderr | regex_search(pushgateway_version_regex, '\\1') | first }}"
|
||||||
|
when: pushgateway_installed
|
||||||
|
|
||||||
|
- name: set pushgateway_local_version to 0
|
||||||
|
set_fact:
|
||||||
|
pushgateway_local_version: "0"
|
||||||
|
when: not pushgateway_installed
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: get checksums
|
||||||
|
set_fact:
|
||||||
|
_checksums: "{{ lookup('url', pushgateway_checksum_url, wantlist=True) }}"
|
||||||
|
|
||||||
|
- name: set pushgateway_checksum
|
||||||
|
set_fact:
|
||||||
|
pushgateway_checksum: "sha256:{{ item.split(' ') | first }}"
|
||||||
|
loop: "{{ _checksums }}"
|
||||||
|
when: "pushgateway_release_file in item"
|
34
roles/pushgateway/templates/pushgateway.service.j2
Normal file
34
roles/pushgateway/templates/pushgateway.service.j2
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Pushgateway
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User={{ pushgateway_user }}
|
||||||
|
Group={{ pushgateway_group }}
|
||||||
|
ExecStart={{ pushgateway_bin_path }}/pushgateway \
|
||||||
|
{% if pushgateway_web_external_url is defined %}
|
||||||
|
--web.external-url={{ pushgateway_web_external_url }} \
|
||||||
|
{% endif %}
|
||||||
|
{% if pushgateway_web_route_prefix is defined %}
|
||||||
|
--web.route-prefix={{ pushgateway_web_route_prefix }} \
|
||||||
|
{% endif %}
|
||||||
|
{% if pushgateway_web_listen_address is defined %}
|
||||||
|
--web.listen-address={{ pushgateway_web_listen_address }} \
|
||||||
|
{% endif %}
|
||||||
|
{% if pushgateway_web_admin_api is defined %}
|
||||||
|
--web.enable-admin-api={{ pushgateway_web_admin_api }} \
|
||||||
|
{% endif %}
|
||||||
|
{% if pushgateway_persistence_file is defined %}
|
||||||
|
--persistence.file={{ pushgateway_persistence_file }} \
|
||||||
|
{% endif %}
|
||||||
|
{% if pushgateway_persistence_interval is defined %}
|
||||||
|
--persistence.interval={{ pushgateway_persistence_interval }} \
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
Restart=always
|
||||||
|
RestartSec=1
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
0
roles/pushgateway/vars/default.yaml
Normal file
0
roles/pushgateway/vars/default.yaml
Normal file
Loading…
Reference in New Issue
Block a user