fix(repo): use_upstream_repo corrections; separate users state
BREAKING CHANGE: The formula has been refactored to accomodate multiple packages, archives, users, and repos. Update your pillars and top states
This commit is contained in:
parent
665e116cee
commit
eda47f71e8
@ -53,6 +53,11 @@ starts the associated prometheus service.
|
||||
|
||||
This state will install the prometheus from archive file only.
|
||||
|
||||
``prometheus.archive.alternatives``
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
This state will install the prometheus linux alternatives for archives only.
|
||||
|
||||
``prometheus.package``
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
@ -107,6 +112,11 @@ This state will remove the prometheus package and has a depency on
|
||||
|
||||
This state will uninstall the prometheus archive-extracted directory only.
|
||||
|
||||
``prometheus.package.archive.alternatives.clean``
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
This state will uninstall the prometheus linux alternatives for archives only.
|
||||
|
||||
``prometheus.package.repo.clean``
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -6,6 +6,8 @@ prometheus:
|
||||
- prometheus
|
||||
- pushgateway
|
||||
- node_explorer
|
||||
# no memcached_exporter in upstream repo - only archive
|
||||
# memcached_exporter
|
||||
|
||||
use_upstream_repo: False
|
||||
use_upstream_archive: True
|
||||
|
@ -5,7 +5,7 @@
|
||||
{%- set tplroot = tpldir.split('/')[0] %}
|
||||
{%- from tplroot ~ "/map.jinja" import prometheus as p with context %}
|
||||
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
|
||||
{%- set sls_archive_install = tplroot ~ '.archive.install' %}
|
||||
{%- set sls_archive_install = tplroot ~ '.archive' %}
|
||||
|
||||
{%- if grains.kernel|lower in ('linux',) and p.linux.altpriority|int > 0 %}
|
||||
|
||||
@ -21,8 +21,6 @@ prometheus-archive-alternatives-install-{{ name }}-home-cmd-run:
|
||||
- name: update-alternatives --install {{ p.dir.basedir }}/{{ bundle }} prometheus-{{ name }}-home {{ p.dir.basedir }}/{{ bundle }} {{p.linux.altpriority}}
|
||||
- watch:
|
||||
- archive: prometheus-archive-install-{{ name }}-archive-extracted
|
||||
- require:
|
||||
- sls: {{ sls_archive_install }}
|
||||
|
||||
prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install:
|
||||
alternatives.install:
|
||||
@ -33,8 +31,6 @@ prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install:
|
||||
- order: 10
|
||||
- watch:
|
||||
- archive: prometheus-archive-install-{{ name }}-archive-extracted
|
||||
- require:
|
||||
- sls: {{ sls_archive_install }}
|
||||
- onlyif: {{ grains.os_family not in ('Suse',) }}
|
||||
|
||||
prometheus-archive-alternatives-install-{{ name }}-home-alternatives-set:
|
||||
|
@ -5,10 +5,10 @@
|
||||
{%- set tplroot = tpldir.split('/')[0] %}
|
||||
{%- from tplroot ~ "/map.jinja" import prometheus as p with context %}
|
||||
{%- set sls_alternatives_clean = tplroot ~ '.archive.alternatives.clean' %}
|
||||
|
||||
{%- if p.use_upstream_archive %}
|
||||
{%- set sls_users_clean = tplroot ~ '.config.users.clean' %}
|
||||
|
||||
include:
|
||||
- {{ sls_users_clean }}
|
||||
- {{ sls_alternatives_clean }}
|
||||
|
||||
{%- for name in p.wanted %}
|
||||
@ -31,13 +31,9 @@ prometheus-archive-clean-{{ name }}-user-absent:
|
||||
|
||||
{%- endfor %}
|
||||
|
||||
prometheus-archive-clean-file-directory:
|
||||
prometheus-archive-clean-basedir-file-directory:
|
||||
file.absent:
|
||||
- names:
|
||||
- {{ p.dir.basedir }}
|
||||
- {{ p.dir.etc }}
|
||||
- {{ p.dir.var }}
|
||||
- name: {{ p.dir.basedir }}
|
||||
- require:
|
||||
- sls: {{ sls_alternatives_clean }}
|
||||
|
||||
{%- endif %}
|
||||
|
@ -6,35 +6,24 @@
|
||||
{%- from tplroot ~ "/map.jinja" import prometheus as p with context %}
|
||||
{%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %}
|
||||
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
|
||||
{%- set sls_users_install = tplroot ~ '.config.users' %}
|
||||
|
||||
prometheus-archive-install-file-directory:
|
||||
include:
|
||||
- {{ sls_users_install }}
|
||||
|
||||
prometheus-config-file-basedir-file-directory:
|
||||
file.directory:
|
||||
- names:
|
||||
- {{ p.dir.basedir }}
|
||||
- {{ p.dir.etc }}
|
||||
- {{ p.dir.var }}
|
||||
- name: {{ p.dir.basedir }}
|
||||
- user: prometheus
|
||||
- group: prometheus
|
||||
- mode: 755
|
||||
- makedirs: True
|
||||
# require:
|
||||
# sls: {{ sls_users_install }}
|
||||
|
||||
{%- for name in p.wanted %}
|
||||
{%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %}
|
||||
|
||||
prometheus-archive-install-{{ name }}-user-present:
|
||||
group.present:
|
||||
- name: {{ name }}
|
||||
- require_in:
|
||||
- user: prometheus-archive-install-{{ name }}-user-present
|
||||
user.present:
|
||||
- name: {{ name }}
|
||||
- shell: /bin/false
|
||||
- createhome: false
|
||||
- groups:
|
||||
- {{ name }}
|
||||
- require_in:
|
||||
- archive: prometheus-archive-install-{{ name }}-archive-extracted
|
||||
|
||||
prometheus-archive-install-{{ name }}-archive-extracted:
|
||||
archive.extracted:
|
||||
- name: {{ p.dir.basedir }}
|
||||
@ -47,6 +36,8 @@ prometheus-archive-install-{{ name }}-archive-extracted:
|
||||
- recurse:
|
||||
- user
|
||||
- group
|
||||
- require:
|
||||
- file: prometheus-config-file-basedir-file-directory
|
||||
|
||||
{%- if name in p.service %}
|
||||
|
||||
@ -59,6 +50,7 @@ prometheus-archive-install-{{ name }}-file-directory:
|
||||
- makedirs: True
|
||||
- require:
|
||||
- archive: prometheus-archive-install-{{ name }}-archive-extracted
|
||||
- file: prometheus-config-file-basedir-file-directory
|
||||
|
||||
prometheus-archive-install-{{ name }}-managed-service:
|
||||
file.managed:
|
||||
@ -82,6 +74,7 @@ prometheus-archive-install-{{ name }}-managed-service:
|
||||
stop: '' #not needed
|
||||
- require:
|
||||
- file: prometheus-archive-install-{{ name }}-file-directory
|
||||
- file: prometheus-config-file-basedir-file-directory
|
||||
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
|
@ -55,3 +55,7 @@ prometheus-config-args-{{ name }}-file-absent:
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
|
||||
prometheus-config-file-args-file-absent:
|
||||
file.absent:
|
||||
- name: {{ prometheus.dir.args }}
|
||||
|
@ -9,8 +9,18 @@
|
||||
{%- set sls_service_install = tplroot ~ '.service' %}
|
||||
|
||||
include:
|
||||
- {{ sls_config_install }}
|
||||
- {{ sls_service_install }}
|
||||
- {{ sls_config_install }}
|
||||
|
||||
prometheus-config-file-args-file-directory:
|
||||
file.directory:
|
||||
- name: {{ prometheus.dir.args }}
|
||||
- user: prometheus
|
||||
- group: prometheus
|
||||
- mode: 755
|
||||
- makedirs: True
|
||||
# require:
|
||||
# sls: {{ sls_config_install }}.users
|
||||
|
||||
{%- for name in prometheus.wanted %}
|
||||
{%- if name in prometheus.config or name in prometheus.service %}
|
||||
@ -28,6 +38,8 @@ prometheus-config-args-{{ name }}-data-dir:
|
||||
- makedirs: True
|
||||
- watch_in:
|
||||
- service: prometheus-service-running-{{ name }}-service-running
|
||||
- require:
|
||||
- file: prometheus-config-file-args-file-directory
|
||||
|
||||
{%- endif %}
|
||||
{%- if args and grains.os_family == 'FreeBSD' %}
|
||||
@ -43,7 +55,7 @@ prometheus-config-args-args-web-listen-address:
|
||||
{%- endif %}
|
||||
{%- if 'collector.textfile.directory' in args.keys() %}
|
||||
|
||||
prometheus-config-args-{{ name }}--collector-textfile-directory:
|
||||
prometheus-config-args-{{ name }}-collector-textfile-directory:
|
||||
sysrc.managed:
|
||||
- name: {{ name }}_textfile_dir
|
||||
- value: {{ args.pop('collector.textfile.directory') }}
|
||||
|
@ -4,3 +4,4 @@
|
||||
include:
|
||||
- .file.clean
|
||||
- .args.clean
|
||||
- .users.clean
|
||||
|
@ -19,3 +19,7 @@ prometheus-config-file-{{ name }}-file-absent:
|
||||
- sls: {{ sls_service_clean }}
|
||||
|
||||
{%- endfor %}
|
||||
|
||||
prometheus-config-file-etc-file-absent:
|
||||
file.absent:
|
||||
- name: {{ prometheus.dir.etc }}
|
||||
|
@ -5,11 +5,23 @@
|
||||
{%- set tplroot = tpldir.split('/')[0] %}
|
||||
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
|
||||
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
|
||||
{%- set sls_archive_install = tplroot ~ '.archive.install' %}
|
||||
{%- set sls_package_install = tplroot ~ '.package.install' %}
|
||||
{%- set sls_users_install = tplroot ~ '.config.users' %}
|
||||
{%- set sls_archive_install = tplroot ~ '.archive' %}
|
||||
{%- set sls_package_install = tplroot ~ '.package' %}
|
||||
|
||||
include:
|
||||
- {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }}
|
||||
- {{ sls_users_install }}
|
||||
|
||||
prometheus-config-file-etc-file-directory:
|
||||
file.directory:
|
||||
- name: {{ prometheus.dir.etc }}
|
||||
- user: prometheus
|
||||
- group: prometheus
|
||||
- mode: 755
|
||||
- makedirs: True
|
||||
# require:
|
||||
# sls: {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }}
|
||||
|
||||
{%- for name in prometheus.wanted %}
|
||||
{%- if name in prometheus.config or name in prometheus.service %}
|
||||
@ -29,7 +41,8 @@ prometheus-config-file-{{ name }}-file-managed:
|
||||
- context:
|
||||
config: {{ '' if name not in prometheus.config else prometheus.config[name]|json }}
|
||||
- require:
|
||||
- sls: {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }}
|
||||
- file: prometheus-config-file-etc-file-directory
|
||||
# user: prometheus-config-user-install-{{ name }}-user-present
|
||||
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
|
@ -2,5 +2,6 @@
|
||||
# vim: ft=sls
|
||||
|
||||
include:
|
||||
- .users
|
||||
- .args
|
||||
- .file
|
||||
|
18
prometheus/config/users/clean.sls
Normal file
18
prometheus/config/users/clean.sls
Normal file
@ -0,0 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=sls
|
||||
|
||||
{#- Get the `tplroot` from `tpldir` #}
|
||||
{%- set tplroot = tpldir.split('/')[0] %}
|
||||
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
|
||||
|
||||
{%- for name in prometheus.wanted %}
|
||||
|
||||
prometheus-config-user-clean-{{ name }}-user-absent:
|
||||
user.absent:
|
||||
- name: {{ name }}
|
||||
group.absent:
|
||||
- name: {{ name }}
|
||||
- require:
|
||||
- user: prometheus-config-user-clean-{{ name }}-user-absent
|
||||
|
||||
{%- endfor %}
|
5
prometheus/config/users/init.sls
Normal file
5
prometheus/config/users/init.sls
Normal file
@ -0,0 +1,5 @@
|
||||
#.-*- coding: utf-8 -*-
|
||||
# vim: ft=sls
|
||||
|
||||
include:
|
||||
- .install
|
22
prometheus/config/users/install.sls
Normal file
22
prometheus/config/users/install.sls
Normal file
@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=sls
|
||||
|
||||
{#- Get the `tplroot` from `tpldir` #}
|
||||
{%- set tplroot = tpldir.split('/')[0] %}
|
||||
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
|
||||
|
||||
{%- for name in prometheus.wanted %}
|
||||
|
||||
prometheus-config-user-install-{{ name }}-user-present:
|
||||
group.present:
|
||||
- name: {{ name }}
|
||||
- require_in:
|
||||
- user: prometheus-config-user-install-{{ name }}-user-present
|
||||
user.present:
|
||||
- name: {{ name }}
|
||||
- shell: /bin/false
|
||||
- createhome: false
|
||||
- groups:
|
||||
- {{ name }}
|
||||
|
||||
{%- endfor %}
|
@ -1,28 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=sls
|
||||
|
||||
{#- Get the `tplroot` from `tpldir` #}
|
||||
{%- set tplroot = tpldir.split('/')[0] %}
|
||||
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
|
||||
|
||||
prometheus-exporters-node-service-dead:
|
||||
service.dead:
|
||||
- name: {{ prometheus.exporters.node.service }}
|
||||
- enable: False
|
||||
|
||||
prometheus-exporters-node-pkg-removed:
|
||||
pkg.removed:
|
||||
- name: {{ prometheus.exporters.node.pkg.name }}
|
||||
- require:
|
||||
- service: prometheus-exporters-node-service-dead
|
||||
|
||||
{# FreeBSD #}
|
||||
{%- if salt['grains.get']('os_family') == 'FreeBSD' %}
|
||||
{%- for parameter in ['args', 'listen_address', 'textfile_dir'] %}
|
||||
prometheus-exporters-node-args-{{ parameter }}:
|
||||
sysrc.absent:
|
||||
- name: node_exporter_{{ parameter }}
|
||||
- require:
|
||||
- service: prometheus-exporters-node-service-dead
|
||||
{%- endfor %}
|
||||
{%- endif %}
|
@ -1,64 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=sls
|
||||
|
||||
{#- Get the `tplroot` from `tpldir` #}
|
||||
{%- set tplroot = tpldir.split('/')[0] %}
|
||||
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
|
||||
{%- from tplroot ~ "/map.jinja" import concat_args %}
|
||||
|
||||
prometheus-exporters-node-pkg-installed:
|
||||
pkg.installed:
|
||||
- name: {{ prometheus.exporters.node.pkg.name }}
|
||||
|
||||
{%- if 'args' in prometheus.exporters.node %}
|
||||
{%- set args = prometheus.exporters.node.get('args', {}) -%}
|
||||
|
||||
{# FreeBSD #}
|
||||
{%- if salt['grains.get']('os_family') == 'FreeBSD' %}
|
||||
{%- if 'web.listen-address' in args.keys() %}
|
||||
{%- set value = args.pop('web.listen-address') %}
|
||||
prometheus-exporters-node-args-web-listen-address:
|
||||
sysrc.managed:
|
||||
- name: node_exporter_listen_address
|
||||
- value: {{ value }}
|
||||
- watch_in:
|
||||
- service: prometheus-exporters-node-service-running
|
||||
{%- endif %}
|
||||
|
||||
{%- if 'collector.textfile.directory' in args.keys() %}
|
||||
{%- set value = args.pop('collector.textfile.directory') %}
|
||||
prometheus-exporters-node-args-collector-textfile-directory:
|
||||
sysrc.managed:
|
||||
- name: node_exporter_textfile_dir
|
||||
- value: {{ value }}
|
||||
- watch_in:
|
||||
- service: prometheus-exporters-node-service-running
|
||||
{%- endif %}
|
||||
|
||||
prometheus-exporters-node-args:
|
||||
sysrc.managed:
|
||||
- name: node_exporter_args
|
||||
# service node_exporter restart tended to hang on FreeBSD
|
||||
# https://github.com/saltstack/salt/issues/44848#issuecomment-487016414
|
||||
- value: "{{ concat_args(args) }} >/dev/null 2>&1"
|
||||
- watch_in:
|
||||
- service: prometheus-exporters-node-service-running
|
||||
|
||||
{# Debian #}
|
||||
{%- elif salt['grains.get']('os_family') == 'Debian'%}
|
||||
prometheus-exporters-node-args:
|
||||
file.managed:
|
||||
- name: {{ prometheus.exporters.node.config_file }}
|
||||
- contents: |
|
||||
ARGS="{{ concat_args(args) }}"
|
||||
- watch_in:
|
||||
- service: prometheus-exporters-node-service-running
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
|
||||
prometheus-exporters-node-service-running:
|
||||
service.running:
|
||||
- name: {{ prometheus.exporters.node.service }}
|
||||
- enable: True
|
||||
- watch:
|
||||
- pkg: prometheus-exporters-node-pkg-installed
|
@ -8,6 +8,9 @@
|
||||
|
||||
include:
|
||||
- {{ sls_config_clean }}
|
||||
{%- if prometheus.use_upstream_repo %}
|
||||
- .repo.clean
|
||||
{%- endif %}
|
||||
|
||||
{%- for name in prometheus.wanted %}
|
||||
{%- if name in prometheus.pkg %}
|
||||
|
@ -5,7 +5,7 @@
|
||||
{%- set tplroot = tpldir.split('/')[0] %}
|
||||
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
|
||||
|
||||
{%- if prometheus.pkg.use_upstream_repo %}
|
||||
{%- if prometheus.use_upstream_repo %}
|
||||
|
||||
include:
|
||||
- .repo
|
||||
|
@ -17,4 +17,9 @@ prometheus-service-clean-{{ name }}-service-dead:
|
||||
{%- endif %}
|
||||
|
||||
{%- endif %}
|
||||
|
||||
{%- endfor %}
|
||||
|
||||
prometheus-config-file-var-file-absent:
|
||||
file.absent:
|
||||
- name: {{ prometheus.dir.var }}
|
||||
|
@ -3,14 +3,24 @@
|
||||
|
||||
{#- Get the `tplroot` from `tpldir` #}
|
||||
{%- set tplroot = tpldir.split('/')[0] %}
|
||||
{%- set sls_config_args = tplroot ~ '.config.args.install' %}
|
||||
{%- set sls_config_file = tplroot ~ '.config.file.install' %}
|
||||
{%- set sls_config_args = tplroot ~ '.config.args' %}
|
||||
{%- set sls_config_file = tplroot ~ '.config.file' %}
|
||||
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
|
||||
|
||||
include:
|
||||
- {{ sls_config_args }}
|
||||
- {{ sls_config_file }}
|
||||
|
||||
prometheus-config-file-var-file-directory:
|
||||
file.directory:
|
||||
- name: {{ prometheus.dir.var }}
|
||||
- user: prometheus
|
||||
- group: prometheus
|
||||
- mode: 755
|
||||
- makedirs: True
|
||||
- require:
|
||||
- file: prometheus-config-file-etc-file-directory
|
||||
|
||||
{%- for name in prometheus.wanted %}
|
||||
{%- if name in prometheus.service %}
|
||||
|
||||
@ -18,8 +28,7 @@ prometheus-service-running-{{ name }}-service-unmasked:
|
||||
service.unmasked:
|
||||
- name: {{ name }}
|
||||
- require:
|
||||
- sls: {{ sls_config_args }}
|
||||
- sls: {{ sls_config_file }}
|
||||
- file: prometheus-config-file-var-file-directory
|
||||
{%- if grains.kernel|lower == 'linux' %}
|
||||
- onlyif:
|
||||
- systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1
|
||||
@ -35,8 +44,7 @@ prometheus-service-running-{{ name }}-service-running:
|
||||
{%- endif %}
|
||||
- require:
|
||||
- service: prometheus-service-running-{{ name }}-service-unmasked
|
||||
- sls: {{ sls_config_args }}
|
||||
- sls: {{ sls_config_file }}
|
||||
- file: prometheus-config-file-var-file-directory
|
||||
{%- if grains.kernel|lower == 'linux' %}
|
||||
- onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1
|
||||
{%- endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user