feat(repository): add support for pkgrepo.managed

BREAKING CHANGE: the variable 'pkg' was renamed 'pkg.name',
  update your pillars
This commit is contained in:
N 2019-06-06 21:15:54 +01:00
parent ea84c92767
commit 907f9a6276
No known key found for this signature in database
GPG Key ID: 55A292EAB4E54067
11 changed files with 91 additions and 9 deletions

View File

@ -2,7 +2,8 @@
# vim: ft=yaml # vim: ft=yaml
--- ---
prometheus: prometheus:
pkg: prometheus pkg:
name: prometheus
config_file: /etc/prometheus/prometheus.yml config_file: /etc/prometheus/prometheus.yml
service: service:
name: prometheus name: prometheus

View File

@ -2,7 +2,16 @@
# vim: ft=yaml # vim: ft=yaml
--- ---
prometheus: prometheus:
pkg: prometheus pkg:
name: prometheus
use_upstream_repo: False
repo:
humanname: prometheus
name: prometheus
comments:
- installed by salt
enabled: 1
gpgcheck: 1
rootgroup: root rootgroup: root
config_file: /etc/prometheus/prometheus.yml config_file: /etc/prometheus/prometheus.yml
config: {} config: {}
@ -12,5 +21,6 @@ prometheus:
group: prometheus group: prometheus
exporters: exporters:
node: node:
pkg: prometheus-node-exporter pkg:
name: prometheus-node-exporter
service: prometheus-node-exporter service: prometheus-node-exporter

View File

@ -12,7 +12,7 @@ prometheus-exporters-node-service-dead:
prometheus-exporters-node-pkg-removed: prometheus-exporters-node-pkg-removed:
pkg.removed: pkg.removed:
- name: {{ prometheus.exporters.node.pkg }} - name: {{ prometheus.exporters.node.pkg.name }}
- require: - require:
- service: prometheus-exporters-node-service-dead - service: prometheus-exporters-node-service-dead

View File

@ -8,7 +8,7 @@
prometheus-exporters-node-pkg-installed: prometheus-exporters-node-pkg-installed:
pkg.installed: pkg.installed:
- name: {{ prometheus.exporters.node.pkg }} - name: {{ prometheus.exporters.node.pkg.name }}
{%- if 'args' in prometheus.exporters.node %} {%- if 'args' in prometheus.exporters.node %}
{%- set args = prometheus.exporters.node.get('args', {}) -%} {%- set args = prometheus.exporters.node.get('args', {}) -%}

View File

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# vim: ft=jinja
#
# Collection of common macros
{%- macro format_kwargs(kwarg) -%}
{%- filter indent(4) %}
{%- for k, v in kwarg|dictsort() %}
- {{ k }}: {{ v }}
{%- endfor %}
{%- endfilter %}
{%- endmacro %}

View File

@ -11,6 +11,7 @@
# osfamilymap: {} # osfamilymap: {}
--- ---
{%- if grains.os == 'MacOS' %} {%- if grains.os == 'MacOS' %}
{% set macos_user = salt['cmd.run']("stat -f '%Su' /dev/console") %}
{% set macos_group = salt['cmd.run']("stat -f '%Sg' /dev/console") %} {% set macos_group = salt['cmd.run']("stat -f '%Sg' /dev/console") %}
{%- endif %} {%- endif %}
@ -20,7 +21,13 @@ Debian:
node: node:
config_file: /etc/default/prometheus-node-exporter config_file: /etc/default/prometheus-node-exporter
RedHat: {} RedHat:
pkg:
use_upstream_repo: True
repo:
baseurl: 'https://packagecloud.io/prometheus-rpm/release/el/$releasever/$basearch'
gpgkey: 'https://packagecloud.io/prometheus-rpm/release/gpgkey gpgkey2=https://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpm'
metadata_expire: 300
Suse: {} Suse: {}
@ -35,7 +42,8 @@ FreeBSD:
config_file: /usr/local/etc/prometheus.yml config_file: /usr/local/etc/prometheus.yml
exporters: exporters:
node: node:
pkg: node_exporter pkg:
name: node_exporter
service: node_exporter service: node_exporter
OpenBSD: OpenBSD:
@ -46,4 +54,5 @@ Solaris: {}
Windows: {} Windows: {}
MacOS: MacOS:
rootuser: {{ macos_user | d('') }}
rootgroup: {{ macos_group | d('') }} rootgroup: {{ macos_group | d('') }}

View File

@ -9,8 +9,13 @@
include: include:
- {{ sls_config_clean }} - {{ sls_config_clean }}
{%- if prometheus.pkg.use_upstream_repo %}
include:
- .repo.clean
{%- endif %}
prometheus-package-clean-pkg-removed: prometheus-package-clean-pkg-removed:
pkg.removed: pkg.removed:
- name: {{ prometheus.pkg }} - name: {{ prometheus.pkg.name }}
- require: - require:
- sls: {{ sls_config_clean }} - sls: {{ sls_config_clean }}

View File

@ -5,6 +5,11 @@
{%- 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 %}
include:
- .repo
{%- endif %}
prometheus-package-install-pkg-installed: prometheus-package-install-pkg-installed:
pkg.installed: pkg.installed:
- name: {{ prometheus.pkg }} - name: {{ prometheus.pkg.name }}

View File

@ -0,0 +1,10 @@
# -*- 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-package-repo-clean-pkgrepo-absent:
pkgrepo.absent:
- name: {{ prometheus.pkg.repo.name }}

View File

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

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# vim: ft=sls
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
{%- if prometheus.pkg.use_upstream_repo %}
{%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %}
prometheus-package-repo-install-pkgrepo-managed:
pkgrepo.managed:
{{- format_kwargs(prometheus.pkg.repo) }}
prometheus-package-repo-install-file-replace-workaround-for-salt-51494:
file.replace:
- name: /etc/yum.repos.d/prometheus.repo
- pattern: ' gpgkey2='
- repl: '\n '
- ignore_if_missing: True
- onlyif: {{ grains.os_family == 'RedHat' }}
{%- endif %}