Skip to content

Commit

Permalink
fix(repo): use_upstream_repo corrections; separate users state
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

The formula has been refactored to accomodate multiple packages,
archives, users, and repos. Update your pillars and top states
  • Loading branch information
noelmcloughlin committed Jun 22, 2019
1 parent 665e116 commit eda47f7
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 136 deletions.
10 changes: 10 additions & 0 deletions docs/README.rst
Expand Up @@ -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``
^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -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``
^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 2 additions & 0 deletions pillar.example
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions prometheus/archive/alternatives/install.sls
Expand Up @@ -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 %}
Expand All @@ -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:
Expand All @@ -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:
Expand Down
12 changes: 4 additions & 8 deletions prometheus/archive/clean.sls
Expand Up @@ -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 %}
Expand All @@ -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 %}
31 changes: 12 additions & 19 deletions prometheus/archive/install.sls
Expand Up @@ -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 }}
Expand All @@ -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 %}
Expand All @@ -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:
Expand All @@ -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 %}
4 changes: 4 additions & 0 deletions prometheus/config/args/clean.sls
Expand Up @@ -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 }}
16 changes: 14 additions & 2 deletions prometheus/config/args/install.sls
Expand Up @@ -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 %}
Expand All @@ -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' %}
Expand All @@ -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') }}
Expand Down
1 change: 1 addition & 0 deletions prometheus/config/clean.sls
Expand Up @@ -4,3 +4,4 @@
include:
- .file.clean
- .args.clean
- .users.clean
4 changes: 4 additions & 0 deletions prometheus/config/file/clean.sls
Expand Up @@ -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 }}
19 changes: 16 additions & 3 deletions prometheus/config/file/install.sls
Expand Up @@ -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 %}
Expand All @@ -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 %}
1 change: 1 addition & 0 deletions prometheus/config/init.sls
Expand Up @@ -2,5 +2,6 @@
# vim: ft=sls

include:
- .users
- .args
- .file
18 changes: 18 additions & 0 deletions prometheus/config/users/clean.sls
@@ -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 changes: 5 additions & 0 deletions prometheus/config/users/init.sls
@@ -0,0 +1,5 @@
#.-*- coding: utf-8 -*-
# vim: ft=sls

include:
- .install
22 changes: 22 additions & 0 deletions prometheus/config/users/install.sls
@@ -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 %}
28 changes: 0 additions & 28 deletions prometheus/exporters/node/clean.sls

This file was deleted.

0 comments on commit eda47f7

Please sign in to comment.