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:
N 2019-06-22 18:24:19 +01:00
parent 665e116cee
commit eda47f71e8
No known key found for this signature in database
GPG Key ID: 55A292EAB4E54067
20 changed files with 137 additions and 136 deletions

View File

@ -53,6 +53,11 @@ starts the associated prometheus service.
This state will install the prometheus from archive file only. 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`` ``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. 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`` ``prometheus.package.repo.clean``
^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -6,6 +6,8 @@ prometheus:
- prometheus - prometheus
- pushgateway - pushgateway
- node_explorer - node_explorer
# no memcached_exporter in upstream repo - only archive
# memcached_exporter
use_upstream_repo: False use_upstream_repo: False
use_upstream_archive: True use_upstream_archive: True

View File

@ -5,7 +5,7 @@
{%- set tplroot = tpldir.split('/')[0] %} {%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- from tplroot ~ "/map.jinja" import prometheus as p with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch 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 %} {%- 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}} - name: update-alternatives --install {{ p.dir.basedir }}/{{ bundle }} prometheus-{{ name }}-home {{ p.dir.basedir }}/{{ bundle }} {{p.linux.altpriority}}
- watch: - watch:
- archive: prometheus-archive-install-{{ name }}-archive-extracted - archive: prometheus-archive-install-{{ name }}-archive-extracted
- require:
- sls: {{ sls_archive_install }}
prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install: prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install:
alternatives.install: alternatives.install:
@ -33,8 +31,6 @@ prometheus-archive-alternatives-install-{{ name }}-home-alternatives-install:
- order: 10 - order: 10
- watch: - watch:
- archive: prometheus-archive-install-{{ name }}-archive-extracted - archive: prometheus-archive-install-{{ name }}-archive-extracted
- require:
- sls: {{ sls_archive_install }}
- onlyif: {{ grains.os_family not in ('Suse',) }} - onlyif: {{ grains.os_family not in ('Suse',) }}
prometheus-archive-alternatives-install-{{ name }}-home-alternatives-set: prometheus-archive-alternatives-install-{{ name }}-home-alternatives-set:

View File

@ -5,10 +5,10 @@
{%- set tplroot = tpldir.split('/')[0] %} {%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- from tplroot ~ "/map.jinja" import prometheus as p with context %}
{%- set sls_alternatives_clean = tplroot ~ '.archive.alternatives.clean' %} {%- set sls_alternatives_clean = tplroot ~ '.archive.alternatives.clean' %}
{%- set sls_users_clean = tplroot ~ '.config.users.clean' %}
{%- if p.use_upstream_archive %}
include: include:
- {{ sls_users_clean }}
- {{ sls_alternatives_clean }} - {{ sls_alternatives_clean }}
{%- for name in p.wanted %} {%- for name in p.wanted %}
@ -31,13 +31,9 @@ prometheus-archive-clean-{{ name }}-user-absent:
{%- endfor %} {%- endfor %}
prometheus-archive-clean-file-directory: prometheus-archive-clean-basedir-file-directory:
file.absent: file.absent:
- names: - name: {{ p.dir.basedir }}
- {{ p.dir.basedir }}
- {{ p.dir.etc }}
- {{ p.dir.var }}
- require: - require:
- sls: {{ sls_alternatives_clean }} - sls: {{ sls_alternatives_clean }}
{%- endif %}

View File

@ -6,35 +6,24 @@
{%- from tplroot ~ "/map.jinja" import prometheus as p with context %} {%- from tplroot ~ "/map.jinja" import prometheus as p with context %}
{%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %} {%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch 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: file.directory:
- names: - name: {{ p.dir.basedir }}
- {{ p.dir.basedir }}
- {{ p.dir.etc }}
- {{ p.dir.var }}
- user: prometheus - user: prometheus
- group: prometheus - group: prometheus
- mode: 755 - mode: 755
- makedirs: True - makedirs: True
# require:
# sls: {{ sls_users_install }}
{%- for name in p.wanted %} {%- for name in p.wanted %}
{%- set bundle = name + '-%s.%s-%s'|format(p.pkg[name]['archive_version'], p.kernel, p.arch) %} {%- 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: prometheus-archive-install-{{ name }}-archive-extracted:
archive.extracted: archive.extracted:
- name: {{ p.dir.basedir }} - name: {{ p.dir.basedir }}
@ -47,6 +36,8 @@ prometheus-archive-install-{{ name }}-archive-extracted:
- recurse: - recurse:
- user - user
- group - group
- require:
- file: prometheus-config-file-basedir-file-directory
{%- if name in p.service %} {%- if name in p.service %}
@ -59,6 +50,7 @@ prometheus-archive-install-{{ name }}-file-directory:
- makedirs: True - makedirs: True
- require: - require:
- archive: prometheus-archive-install-{{ name }}-archive-extracted - archive: prometheus-archive-install-{{ name }}-archive-extracted
- file: prometheus-config-file-basedir-file-directory
prometheus-archive-install-{{ name }}-managed-service: prometheus-archive-install-{{ name }}-managed-service:
file.managed: file.managed:
@ -82,6 +74,7 @@ prometheus-archive-install-{{ name }}-managed-service:
stop: '' #not needed stop: '' #not needed
- require: - require:
- file: prometheus-archive-install-{{ name }}-file-directory - file: prometheus-archive-install-{{ name }}-file-directory
- file: prometheus-config-file-basedir-file-directory
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}

View File

@ -55,3 +55,7 @@ prometheus-config-args-{{ name }}-file-absent:
{%- endif %} {%- endif %}
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}
prometheus-config-file-args-file-absent:
file.absent:
- name: {{ prometheus.dir.args }}

View File

@ -9,8 +9,18 @@
{%- set sls_service_install = tplroot ~ '.service' %} {%- set sls_service_install = tplroot ~ '.service' %}
include: include:
- {{ sls_config_install }}
- {{ sls_service_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 %} {%- for name in prometheus.wanted %}
{%- if name in prometheus.config or name in prometheus.service %} {%- if name in prometheus.config or name in prometheus.service %}
@ -28,6 +38,8 @@ prometheus-config-args-{{ name }}-data-dir:
- makedirs: True - makedirs: True
- watch_in: - watch_in:
- service: prometheus-service-running-{{ name }}-service-running - service: prometheus-service-running-{{ name }}-service-running
- require:
- file: prometheus-config-file-args-file-directory
{%- endif %} {%- endif %}
{%- if args and grains.os_family == 'FreeBSD' %} {%- if args and grains.os_family == 'FreeBSD' %}
@ -43,7 +55,7 @@ prometheus-config-args-args-web-listen-address:
{%- endif %} {%- endif %}
{%- if 'collector.textfile.directory' in args.keys() %} {%- if 'collector.textfile.directory' in args.keys() %}
prometheus-config-args-{{ name }}--collector-textfile-directory: prometheus-config-args-{{ name }}-collector-textfile-directory:
sysrc.managed: sysrc.managed:
- name: {{ name }}_textfile_dir - name: {{ name }}_textfile_dir
- value: {{ args.pop('collector.textfile.directory') }} - value: {{ args.pop('collector.textfile.directory') }}

View File

@ -4,3 +4,4 @@
include: include:
- .file.clean - .file.clean
- .args.clean - .args.clean
- .users.clean

View File

@ -19,3 +19,7 @@ prometheus-config-file-{{ name }}-file-absent:
- sls: {{ sls_service_clean }} - sls: {{ sls_service_clean }}
{%- endfor %} {%- endfor %}
prometheus-config-file-etc-file-absent:
file.absent:
- name: {{ prometheus.dir.etc }}

View File

@ -5,11 +5,23 @@
{%- set tplroot = tpldir.split('/')[0] %} {%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- from tplroot ~ "/map.jinja" import prometheus with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
{%- set sls_archive_install = tplroot ~ '.archive.install' %} {%- set sls_users_install = tplroot ~ '.config.users' %}
{%- set sls_package_install = tplroot ~ '.package.install' %} {%- set sls_archive_install = tplroot ~ '.archive' %}
{%- set sls_package_install = tplroot ~ '.package' %}
include: include:
- {{ sls_archive_install if prometheus.use_upstream_archive else sls_package_install }} - {{ 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 %} {%- for name in prometheus.wanted %}
{%- if name in prometheus.config or name in prometheus.service %} {%- if name in prometheus.config or name in prometheus.service %}
@ -29,7 +41,8 @@ prometheus-config-file-{{ name }}-file-managed:
- context: - context:
config: {{ '' if name not in prometheus.config else prometheus.config[name]|json }} config: {{ '' if name not in prometheus.config else prometheus.config[name]|json }}
- require: - 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 %} {%- endif %}
{%- endfor %} {%- endfor %}

View File

@ -2,5 +2,6 @@
# vim: ft=sls # vim: ft=sls
include: include:
- .users
- .args - .args
- .file - .file

View 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 %}

View File

@ -0,0 +1,5 @@
#.-*- coding: utf-8 -*-
# vim: ft=sls
include:
- .install

View 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 %}

View File

@ -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 %}

View File

@ -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

View File

@ -8,6 +8,9 @@
include: include:
- {{ sls_config_clean }} - {{ sls_config_clean }}
{%- if prometheus.use_upstream_repo %}
- .repo.clean
{%- endif %}
{%- for name in prometheus.wanted %} {%- for name in prometheus.wanted %}
{%- if name in prometheus.pkg %} {%- if name in prometheus.pkg %}

View File

@ -5,7 +5,7 @@
{%- set tplroot = tpldir.split('/')[0] %} {%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- from tplroot ~ "/map.jinja" import prometheus with context %}
{%- if prometheus.pkg.use_upstream_repo %} {%- if prometheus.use_upstream_repo %}
include: include:
- .repo - .repo

View File

@ -17,4 +17,9 @@ prometheus-service-clean-{{ name }}-service-dead:
{%- endif %} {%- endif %}
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}
prometheus-config-file-var-file-absent:
file.absent:
- name: {{ prometheus.dir.var }}

View File

@ -3,14 +3,24 @@
{#- Get the `tplroot` from `tpldir` #} {#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %} {%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_config_args = tplroot ~ '.config.args.install' %} {%- set sls_config_args = tplroot ~ '.config.args' %}
{%- set sls_config_file = tplroot ~ '.config.file.install' %} {%- set sls_config_file = tplroot ~ '.config.file' %}
{%- from tplroot ~ "/map.jinja" import prometheus with context %} {%- from tplroot ~ "/map.jinja" import prometheus with context %}
include: include:
- {{ sls_config_args }} - {{ sls_config_args }}
- {{ sls_config_file }} - {{ 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 %} {%- for name in prometheus.wanted %}
{%- if name in prometheus.service %} {%- if name in prometheus.service %}
@ -18,8 +28,7 @@ prometheus-service-running-{{ name }}-service-unmasked:
service.unmasked: service.unmasked:
- name: {{ name }} - name: {{ name }}
- require: - require:
- sls: {{ sls_config_args }} - file: prometheus-config-file-var-file-directory
- sls: {{ sls_config_file }}
{%- if grains.kernel|lower == 'linux' %} {%- if grains.kernel|lower == 'linux' %}
- onlyif: - onlyif:
- systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 - systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1
@ -35,8 +44,7 @@ prometheus-service-running-{{ name }}-service-running:
{%- endif %} {%- endif %}
- require: - require:
- service: prometheus-service-running-{{ name }}-service-unmasked - service: prometheus-service-running-{{ name }}-service-unmasked
- sls: {{ sls_config_args }} - file: prometheus-config-file-var-file-directory
- sls: {{ sls_config_file }}
{%- if grains.kernel|lower == 'linux' %} {%- if grains.kernel|lower == 'linux' %}
- onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1 - onlyif: systemctl list-unit-files | grep {{ name }} >/dev/null 2>&1
{%- endif %} {%- endif %}