2019-06-08 19:39:21 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: ft=sls
|
|
|
|
|
|
|
|
{%- set tplroot = tpldir.split('/')[0] %}
|
2019-06-17 23:02:51 +02:00
|
|
|
{%- from tplroot ~ "/map.jinja" import prometheus as p with context %}
|
2020-05-14 01:27:23 +02:00
|
|
|
{%- from tplroot ~ "/files/macros.jinja" import format_kwargs with context %}
|
2019-06-19 01:23:45 +02:00
|
|
|
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
|
2020-05-14 01:27:23 +02:00
|
|
|
{%- set sls_config_users = tplroot ~ '.config.users' %}
|
2019-06-08 19:39:21 +02:00
|
|
|
|
2019-06-22 19:24:19 +02:00
|
|
|
include:
|
2020-05-14 01:27:23 +02:00
|
|
|
- {{ sls_config_users }}
|
2019-06-22 19:24:19 +02:00
|
|
|
|
2020-05-14 01:27:23 +02:00
|
|
|
prometheus-archive-install-prerequisites:
|
2020-10-19 14:57:29 +02:00
|
|
|
{%- if grains.os != 'Windows' %}
|
2020-05-14 01:27:23 +02:00
|
|
|
pkg.installed:
|
|
|
|
- names: {{ p.pkg.deps|json }}
|
2020-10-19 14:57:29 +02:00
|
|
|
{%- endif %}
|
2019-06-20 02:36:58 +02:00
|
|
|
file.directory:
|
2020-05-14 01:27:23 +02:00
|
|
|
- name: {{ p.dir.var }}
|
2019-06-20 02:36:58 +02:00
|
|
|
- makedirs: True
|
2019-06-22 23:34:37 +02:00
|
|
|
- require:
|
2020-05-14 01:27:23 +02:00
|
|
|
- sls: {{ sls_config_users }}
|
2020-10-19 14:57:29 +02:00
|
|
|
{%- if grains.os != 'Windows' %}
|
|
|
|
- mode: 755
|
|
|
|
- user: {{ p.identity.rootuser }}
|
|
|
|
- group: {{ p.identity.rootgroup }}
|
|
|
|
{%- endif %}
|
2019-06-20 02:36:58 +02:00
|
|
|
|
2020-05-14 01:27:23 +02:00
|
|
|
{%- for name in p.wanted.component %}
|
2019-06-17 23:02:51 +02:00
|
|
|
|
2020-11-10 14:19:30 +01:00
|
|
|
prometheus-archive-directory-{{ name }}:
|
2020-05-14 01:27:23 +02:00
|
|
|
file.directory:
|
|
|
|
- name: {{ p.pkg.component[name]['path'] }}
|
|
|
|
- makedirs: True
|
2020-10-19 14:57:29 +02:00
|
|
|
{%- if grains.os != 'Windows' %}
|
|
|
|
- user: {{ p.identity.rootuser }}
|
|
|
|
- group: {{ p.identity.rootgroup }}
|
|
|
|
- mode: '0755'
|
2019-06-16 02:22:14 +02:00
|
|
|
- recurse:
|
|
|
|
- user
|
|
|
|
- group
|
2020-05-14 01:27:23 +02:00
|
|
|
- mode
|
2020-10-19 14:57:29 +02:00
|
|
|
{%- endif %}
|
2020-11-10 14:19:30 +01:00
|
|
|
prometheus-archive-install-{{ name }}:
|
|
|
|
{%- if p.pkg.component.get(name).get('archive').get('tar', true) %}
|
2020-05-14 01:27:23 +02:00
|
|
|
archive.extracted:
|
|
|
|
{{- format_kwargs(p.pkg.component[name]['archive']) }}
|
|
|
|
- trim_output: true
|
|
|
|
- enforce_toplevel: false
|
|
|
|
- options: --strip-components=1
|
2020-10-19 14:57:29 +02:00
|
|
|
- force: {{ p.force }}
|
2020-05-14 01:27:23 +02:00
|
|
|
- retry: {{ p.retry_option|json }}
|
2019-06-22 19:24:19 +02:00
|
|
|
- require:
|
2020-11-10 14:19:30 +01:00
|
|
|
- file: prometheus-archive-directory-{{ name }}
|
|
|
|
{%- if grains.os != 'Windows' %}
|
2020-10-19 14:57:29 +02:00
|
|
|
- user: {{ p.identity.rootuser }}
|
|
|
|
- group: {{ p.identity.rootgroup }}
|
2020-11-10 14:19:30 +01:00
|
|
|
{%- endif %}
|
|
|
|
{% else %}
|
|
|
|
file.managed:
|
|
|
|
- name: {{ p.pkg.component[name]['path'] }}/{{ name }}
|
|
|
|
- source: {{ p.pkg.component[name]['archive']['source'] }}
|
|
|
|
- source_hash: {{ p.pkg.component[name]['archive']['source_hash'] }}
|
|
|
|
- mode: '0755'
|
|
|
|
- require:
|
|
|
|
- file: prometheus-archive-directory-{{ name }}
|
|
|
|
{%- if grains.os != 'Windows' %}
|
|
|
|
- user: {{ p.identity.rootuser }}
|
|
|
|
- group: {{ p.identity.rootgroup }}
|
|
|
|
{%- endif %}
|
2020-10-19 14:57:29 +02:00
|
|
|
{%- endif %}
|
|
|
|
{%- if (grains.kernel|lower == 'linux' and p.linux.altpriority|int <= 0) or grains.os_family|lower in ('macos', 'arch') %}
|
2020-05-14 01:27:23 +02:00
|
|
|
{%- if 'commands' in p.pkg.component[name] and p.pkg.component[name]['commands'] is iterable %}
|
|
|
|
{%- for cmd in p.pkg.component[name]['commands'] %}
|
2019-06-19 01:23:45 +02:00
|
|
|
|
2020-05-14 01:27:23 +02:00
|
|
|
prometheus-archive-install-{{ name }}-file-symlink-{{ cmd }}:
|
|
|
|
file.symlink:
|
|
|
|
{%- if 'service' in p.pkg.component[name] %}
|
|
|
|
- name: {{ p.dir.symlink }}/sbin/{{ cmd }}
|
|
|
|
{%- else %}
|
|
|
|
- name: {{ p.dir.symlink }}/bin/{{ cmd }}
|
|
|
|
{% endif %}
|
|
|
|
- target: {{ p.pkg.component[name]['path'] }}/{{ cmd }}
|
|
|
|
- force: True
|
|
|
|
- require:
|
2020-11-10 14:19:30 +01:00
|
|
|
{%- if p.pkg.component.get(name).get('archive').get('tar', true) %}
|
2020-05-14 01:27:23 +02:00
|
|
|
- archive: prometheus-archive-install-{{ name }}
|
2020-11-10 14:19:30 +01:00
|
|
|
{% else %}
|
|
|
|
- file: prometheus-archive-install-{{ name }}
|
|
|
|
{% endif %}
|
2020-05-14 01:27:23 +02:00
|
|
|
|
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|
|
|
|
{%- endif %}
|
|
|
|
{%- if 'service' in p.pkg.component[name] and p.pkg.component[name]['service'] is mapping %}
|
2019-10-09 19:18:44 +02:00
|
|
|
|
2019-06-20 02:36:58 +02:00
|
|
|
prometheus-archive-install-{{ name }}-file-directory:
|
|
|
|
file.directory:
|
2020-10-19 14:57:29 +02:00
|
|
|
- name: {{ p.dir.var }}{{ p.div }}{{ name }}
|
|
|
|
- makedirs: True
|
|
|
|
{%- if grains.os != 'Windows' %}
|
2019-06-20 02:36:58 +02:00
|
|
|
- user: {{ name }}
|
|
|
|
- group: {{ name }}
|
2020-05-14 01:27:23 +02:00
|
|
|
- mode: '0755'
|
2019-06-20 02:36:58 +02:00
|
|
|
- require:
|
2020-11-03 10:34:46 +01:00
|
|
|
- user: prometheus-config-users-install-{{ name }}-user-present
|
|
|
|
- group: prometheus-config-users-install-{{ name }}-group-present
|
2019-06-20 02:36:58 +02:00
|
|
|
|
2020-10-19 14:57:29 +02:00
|
|
|
{%- endif %}
|
2020-08-25 16:30:05 +02:00
|
|
|
{%- if grains.kernel|lower == 'linux' %}
|
|
|
|
|
2019-06-20 02:36:58 +02:00
|
|
|
prometheus-archive-install-{{ name }}-managed-service:
|
2019-06-19 01:23:45 +02:00
|
|
|
file.managed:
|
2020-08-25 16:28:28 +02:00
|
|
|
- name: {{ p.dir.service }}/{{ p.pkg.component[name]['service'].get('name', name) }}.service
|
2019-06-19 01:23:45 +02:00
|
|
|
- source: {{ files_switch(['systemd.ini.jinja'],
|
2020-05-14 01:27:23 +02:00
|
|
|
lookup='prometheus-archive-install-' ~ name ~ '-managed-service'
|
2019-06-19 01:23:45 +02:00
|
|
|
)
|
|
|
|
}}
|
2020-05-14 01:27:23 +02:00
|
|
|
- mode: '0644'
|
|
|
|
- user: {{ p.identity.rootuser }}
|
|
|
|
- group: {{ p.identity.rootgroup }}
|
2019-06-19 01:23:45 +02:00
|
|
|
- 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 }}
|
2020-05-14 01:27:23 +02:00
|
|
|
stop: ''
|
2020-08-25 19:13:57 +02:00
|
|
|
{%- if name in ('node_exporter', 'consul_exporter') or 'config_file' not in p.pkg.component[name] %}
|
2020-11-09 15:25:51 +01:00
|
|
|
{%- set args = [] %}
|
|
|
|
{%- for param, value in p.pkg.component.get(name).get('service').get('args', {}).items() %}
|
|
|
|
{% do args.append("--" ~ param ~ "=" ~ value ) %}
|
|
|
|
{%- endfor %}
|
|
|
|
start: {{ p.pkg.component[name]['path'] }}/{{ name }} {{ args|join(' ') }}
|
2020-05-14 01:27:23 +02:00
|
|
|
{%- else %}
|
|
|
|
start: {{ p.pkg.component[name]['path'] }}/{{ name }} --config.file {{ p.pkg.component[name]['config_file'] }} # noqa 204
|
|
|
|
{%- endif %}
|
2019-06-20 02:36:58 +02:00
|
|
|
- require:
|
|
|
|
- file: prometheus-archive-install-{{ name }}-file-directory
|
2020-11-10 14:19:30 +01:00
|
|
|
{%- if p.pkg.component.get(name).get('archive').get('tar', true) %}
|
2020-05-14 01:27:23 +02:00
|
|
|
- archive: prometheus-archive-install-{{ name }}
|
2020-11-10 14:19:30 +01:00
|
|
|
{% else %}
|
|
|
|
- file: prometheus-archive-install-{{ name }}
|
|
|
|
{% endif %}
|
2020-11-03 10:34:46 +01:00
|
|
|
- user: prometheus-config-users-install-{{ name }}-user-present
|
|
|
|
- group: prometheus-config-users-install-{{ name }}-group-present
|
2019-06-23 14:55:08 +02:00
|
|
|
cmd.run:
|
|
|
|
- name: systemctl daemon-reload
|
|
|
|
- require:
|
2020-11-10 14:19:30 +01:00
|
|
|
{%- if p.pkg.component.get(name).get('archive').get('tar', true) %}
|
2020-05-14 01:27:23 +02:00
|
|
|
- archive: prometheus-archive-install-{{ name }}
|
2020-11-10 14:19:30 +01:00
|
|
|
{% else %}
|
|
|
|
- file: prometheus-archive-install-{{ name }}
|
|
|
|
{% endif %}
|
2019-06-19 01:23:45 +02:00
|
|
|
|
2020-10-19 14:57:29 +02:00
|
|
|
{%- endif %}{# linux #}
|
|
|
|
{%- endif %}{# service #}
|
2020-05-14 01:27:23 +02:00
|
|
|
{%- endfor %}
|