Skip to content

Commit

Permalink
feat(repository): add support for pkgrepo.managed
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the variable 'pkg' was renamed 'pkg.name',
  update your pillars
  • Loading branch information
noelmcloughlin committed Jun 12, 2019
1 parent ea84c92 commit 907f9a6
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 9 deletions.
3 changes: 2 additions & 1 deletion pillar.example
Expand Up @@ -2,7 +2,8 @@
# vim: ft=yaml
---
prometheus:
pkg: prometheus
pkg:
name: prometheus
config_file: /etc/prometheus/prometheus.yml
service:
name: prometheus
Expand Down
14 changes: 12 additions & 2 deletions prometheus/defaults.yaml
Expand Up @@ -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: {}
Expand All @@ -12,5 +21,6 @@ prometheus:
group: prometheus
exporters:
node:
pkg: prometheus-node-exporter
pkg:
name: prometheus-node-exporter
service: prometheus-node-exporter
2 changes: 1 addition & 1 deletion prometheus/exporters/node/clean.sls
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion prometheus/exporters/node/init.sls
Expand Up @@ -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', {}) -%}
Expand Down
14 changes: 14 additions & 0 deletions prometheus/jinja/macros.jinja
@@ -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 %}
13 changes: 11 additions & 2 deletions prometheus/osfamilymap.yaml
Expand Up @@ -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 %}

Expand All @@ -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: {}

Expand All @@ -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:
Expand All @@ -46,4 +54,5 @@ Solaris: {}
Windows: {}

MacOS:
rootuser: {{ macos_user | d('') }}
rootgroup: {{ macos_group | d('') }}
7 changes: 6 additions & 1 deletion prometheus/package/clean.sls
Expand Up @@ -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 }}
7 changes: 6 additions & 1 deletion prometheus/package/install.sls
Expand Up @@ -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 }}
10 changes: 10 additions & 0 deletions prometheus/package/repo/clean.sls
@@ -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 }}
5 changes: 5 additions & 0 deletions prometheus/package/repo/init.sls
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .install
23 changes: 23 additions & 0 deletions prometheus/package/repo/install.sls
@@ -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 %}

0 comments on commit 907f9a6

Please sign in to comment.