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
---
prometheus:
pkg: prometheus
pkg:
name: prometheus
config_file: /etc/prometheus/prometheus.yml
service:
name: prometheus

View File

@ -2,7 +2,16 @@
# vim: ft=yaml
---
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
config_file: /etc/prometheus/prometheus.yml
config: {}
@ -12,5 +21,6 @@ prometheus:
group: prometheus
exporters:
node:
pkg: prometheus-node-exporter
pkg:
name: prometheus-node-exporter
service: prometheus-node-exporter

View File

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

View File

@ -8,7 +8,7 @@
prometheus-exporters-node-pkg-installed:
pkg.installed:
- name: {{ prometheus.exporters.node.pkg }}
- name: {{ prometheus.exporters.node.pkg.name }}
{%- if 'args' in prometheus.exporters.node %}
{%- 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: {}
---
{%- 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") %}
{%- endif %}
@ -20,7 +21,13 @@ Debian:
node:
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: {}
@ -35,7 +42,8 @@ FreeBSD:
config_file: /usr/local/etc/prometheus.yml
exporters:
node:
pkg: node_exporter
pkg:
name: node_exporter
service: node_exporter
OpenBSD:
@ -46,4 +54,5 @@ Solaris: {}
Windows: {}
MacOS:
rootuser: {{ macos_user | d('') }}
rootgroup: {{ macos_group | d('') }}

View File

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

View File

@ -4,7 +4,12 @@
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import prometheus with context %}
{%- if prometheus.pkg.use_upstream_repo %}
include:
- .repo
{%- endif %}
prometheus-package-install-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 %}