diff --git a/pillar.example b/pillar.example index 5feb67c..b482dc6 100644 --- a/pillar.example +++ b/pillar.example @@ -2,7 +2,8 @@ # vim: ft=yaml --- prometheus: - pkg: prometheus + pkg: + name: prometheus config_file: /etc/prometheus/prometheus.yml service: name: prometheus diff --git a/prometheus/defaults.yaml b/prometheus/defaults.yaml index cf551cd..691bfab 100644 --- a/prometheus/defaults.yaml +++ b/prometheus/defaults.yaml @@ -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 diff --git a/prometheus/exporters/node/clean.sls b/prometheus/exporters/node/clean.sls index cbd4030..14401e2 100644 --- a/prometheus/exporters/node/clean.sls +++ b/prometheus/exporters/node/clean.sls @@ -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 diff --git a/prometheus/exporters/node/init.sls b/prometheus/exporters/node/init.sls index 29ec372..f8f7534 100644 --- a/prometheus/exporters/node/init.sls +++ b/prometheus/exporters/node/init.sls @@ -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', {}) -%} diff --git a/prometheus/jinja/macros.jinja b/prometheus/jinja/macros.jinja new file mode 100644 index 0000000..f736111 --- /dev/null +++ b/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 %} diff --git a/prometheus/osfamilymap.yaml b/prometheus/osfamilymap.yaml index e0da13b..f1c306d 100644 --- a/prometheus/osfamilymap.yaml +++ b/prometheus/osfamilymap.yaml @@ -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('') }} diff --git a/prometheus/package/clean.sls b/prometheus/package/clean.sls index b4e5a80..d0c530c 100644 --- a/prometheus/package/clean.sls +++ b/prometheus/package/clean.sls @@ -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 }} diff --git a/prometheus/package/install.sls b/prometheus/package/install.sls index 873c4a7..633b121 100644 --- a/prometheus/package/install.sls +++ b/prometheus/package/install.sls @@ -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 }} diff --git a/prometheus/package/repo/clean.sls b/prometheus/package/repo/clean.sls new file mode 100644 index 0000000..dd21c00 --- /dev/null +++ b/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 }} diff --git a/prometheus/package/repo/init.sls b/prometheus/package/repo/init.sls new file mode 100644 index 0000000..d3e5518 --- /dev/null +++ b/prometheus/package/repo/init.sls @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .install diff --git a/prometheus/package/repo/install.sls b/prometheus/package/repo/install.sls new file mode 100644 index 0000000..2b0164b --- /dev/null +++ b/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 %}