prometheus-formula/prometheus/archive/install.sls

90 lines
2.8 KiB
Plaintext
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: ft=sls
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import prometheus as p with context %}
{%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %}
2019-06-19 01:23:45 +02:00
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
{%- set sls_users_install = tplroot ~ '.config.users' %}
include:
- {{ sls_users_install }}
prometheus-config-file-basedir-file-directory:
2019-06-20 02:36:58 +02:00
file.directory:
- name: {{ p.dir.basedir }}
2019-06-20 02:36:58 +02:00
- user: prometheus
- group: prometheus
- mode: 755
- makedirs: True
- require:
- sls: '{{ sls_users_install }}.*'
2019-06-20 02:36:58 +02:00
{%- for name in p.wanted %}
{%- if name in p.pkg %}
{%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %}
2019-06-20 02:36:58 +02:00
prometheus-archive-install-{{ name }}-archive-extracted:
archive.extracted:
2019-06-20 02:36:58 +02:00
- name: {{ p.dir.basedir }}
- source: {{ p.archive.uri }}/{{ name }}/releases/download/v{{ p.pkg[name]['archive_version']
+ '/' + bundle + '.' + p.archive.suffix }}
- source_hash: {{ p.pkg[name]['archive_hash'] }}
2019-06-20 02:36:58 +02:00
- user: {{ name }}
- group: {{ name }}
{{- format_kwargs(p.archive.kwargs) }}
- recurse:
- user
- group
- require:
- file: prometheus-config-file-basedir-file-directory
2019-06-19 01:23:45 +02:00
{%- if name in p.service %}
2019-06-20 02:36:58 +02:00
prometheus-archive-install-{{ name }}-file-directory:
file.directory:
- name: {{ p.dir.var }}/{{ name }}
- user: {{ name }}
- group: {{ name }}
- mode: 755
- makedirs: True
- require:
- archive: prometheus-archive-install-{{ name }}-archive-extracted
- file: prometheus-config-file-basedir-file-directory
2019-06-20 02:36:58 +02:00
{%- if grains.os_family not in ('MacOS', 'FreeBSD', 'Windows') %}
2019-06-20 02:36:58 +02:00
prometheus-archive-install-{{ name }}-managed-service:
2019-06-19 01:23:45 +02:00
file.managed:
2019-06-20 02:36:58 +02:00
- name: {{ p.dir.service }}/{{ name }}.service
2019-06-19 01:23:45 +02:00
- source: {{ files_switch(['systemd.ini.jinja'],
2019-12-12 06:38:58 +01:00
lookup='prometheus-archive-install-managed-service'
2019-06-19 01:23:45 +02:00
)
}}
- mode: 644
- user: root
- group: {{ p.rootgroup }}
- makedirs: True
- template: jinja
- context:
2019-06-20 02:36:58 +02:00
desc: prometheus - {{ name }} service
name: {{ name }}
user: {{ name }}
group: {{ name }}
workdir: {{ p.dir.var }}/{{ name }}
start: {{ p.dir.basedir }}/{{ bundle }}/{{ name }} --config.file {{ p.dir.etc }}/{{ name }}.yml
stop: '' #not needed
- require:
- file: prometheus-archive-install-{{ name }}-file-directory
- file: prometheus-config-file-basedir-file-directory
cmd.run:
- name: systemctl daemon-reload
- require:
- file: prometheus-archive-install-{{ name }}-managed-service
2019-06-19 01:23:45 +02:00
{%- endif %}
{%- endif %}
2019-06-20 02:36:58 +02:00
{%- endif %}
{%- endfor %}