From ded31578d26336305c51544380decd2112aba2eb Mon Sep 17 00:00:00 2001 From: N Date: Fri, 7 Jun 2019 00:49:27 +0100 Subject: [PATCH] feat(repository): support rpm-based linux distros BREAKING CHANGE: the parameter `pkg` is now a dictionary. References to `grafana.pkg` should be changed to `grafana.pkg.name`. --- grafana/defaults.yaml | 13 ++++++++-- grafana/jinja/macros.jinja | 14 +++++++++++ grafana/osfamilymap.yaml | 41 +++++++++++++++++++++++++------- grafana/package/clean.sls | 7 +++++- grafana/package/install.sls | 18 +++++--------- grafana/package/repo/clean.sls | 10 ++++++++ grafana/package/repo/init.sls | 5 ++++ grafana/package/repo/install.sls | 15 ++++++++++++ pillar.example | 15 +++++++----- 9 files changed, 109 insertions(+), 29 deletions(-) create mode 100644 grafana/jinja/macros.jinja create mode 100644 grafana/package/repo/clean.sls create mode 100644 grafana/package/repo/init.sls create mode 100644 grafana/package/repo/install.sls diff --git a/grafana/defaults.yaml b/grafana/defaults.yaml index 2903025..e82d742 100644 --- a/grafana/defaults.yaml +++ b/grafana/defaults.yaml @@ -2,8 +2,17 @@ # vim: ft=yaml --- grafana: - pkg: grafana - pkgrepo: False + pkg: + name: grafana + use_upstream_repo: False + repo: + humanname: grafana + name: grafana + comments: + - installed by salt + enabled: 1 + gpgcheck: 1 + group: grafana config_file: /etc/grafana/grafana.ini config: {} diff --git a/grafana/jinja/macros.jinja b/grafana/jinja/macros.jinja new file mode 100644 index 0000000..f736111 --- /dev/null +++ b/grafana/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/grafana/osfamilymap.yaml b/grafana/osfamilymap.yaml index bd0f909..f5d0436 100644 --- a/grafana/osfamilymap.yaml +++ b/grafana/osfamilymap.yaml @@ -11,19 +11,42 @@ # 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 %} Debian: - pkgrepo: - humanname: grafana_official - name: deb https://packages.grafana.com/oss/deb stable main - file: /etc/apt/sources.list.d/grafana.list - key_url: https://packages.grafana.com/gpg.key + pkg: + use_upstream_repo: True + repo: + humanname: grafana_official + name: deb https://packages.grafana.com/oss/deb stable main + file: /etc/apt/sources.list.d/grafana.list + key_url: https://packages.grafana.com/gpg.key -RedHat: {} +RedHat: + pkg: + use_upstream_repo: True + repo: + baseurl: https://packages.grafana.com/oss/rpm-beta + repo_gpgcheck: 1 + gpgkey: https://packages.grafana.com/gpg.key + sslverify: 1 + sslcacert: /etc/pki/tls/certs/ca-bundle.crt + comments: + - instructions from https://grafana.com/docs/installation/rpm/ -Suse: {} +Suse: + pkg: + use_upstream_repo: True + repo: + baseurl: https://packages.grafana.com/oss/rpm-beta + repo_gpgcheck: 1 + gpgkey: https://packages.grafana.com/gpg.key + sslverify: 1 + sslcacert: /etc/pki/tls/certs/ca-bundle.crt + comments: + - instructions from https://grafana.com/docs/installation/rpm/ Gentoo: {} @@ -32,7 +55,8 @@ Arch: {} Alpine: {} FreeBSD: - pkg: grafana5 + pkg: + name: grafana5 config_file: /usr/local/etc/grafana.conf config: paths: @@ -52,6 +76,7 @@ Solaris: {} Windows: {} MacOS: + rootuser: {{ macos_user | d('') }} rootgroup: {{ macos_group | d('') }} service: group: {{ macos_group | d('') }} diff --git a/grafana/package/clean.sls b/grafana/package/clean.sls index 4da6d5b..9e39e8c 100644 --- a/grafana/package/clean.sls +++ b/grafana/package/clean.sls @@ -9,8 +9,13 @@ include: - {{ sls_config_clean }} + {%- if grafana.pkg.use_upstream_repo %} +include: + - .repo.clean + {%- endif %} + grafana-package-clean-pkg-removed: pkg.removed: - - name: {{ grafana.pkg }} + - name: {{ grafana.pkg.name }} - require: - sls: {{ sls_config_clean }} diff --git a/grafana/package/install.sls b/grafana/package/install.sls index 42f1b81..a4a9d4b 100644 --- a/grafana/package/install.sls +++ b/grafana/package/install.sls @@ -4,18 +4,12 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} {%- from tplroot ~ "/map.jinja" import grafana with context %} - -{% if grafana.pkgrepo %} -grafana-package-install-pkgrepo-managed: - pkgrepo.managed: - - humanname: {{ grafana.pkgrepo.humanname }} - - name: {{ grafana.pkgrepo.name }} - - file: {{ grafana.pkgrepo.file}} - - key_url: {{ grafana.pkgrepo.key_url}} - - require_in: - - pkg: grafana-package-install-pkg-installed -{% endif %} + + {%- if grafana.pkg.use_upstream_repo %} +include: + - .repo + {%- endif %} grafana-package-install-pkg-installed: pkg.installed: - - name: {{ grafana.pkg }} + - name: {{ grafana.pkg.name }} diff --git a/grafana/package/repo/clean.sls b/grafana/package/repo/clean.sls new file mode 100644 index 0000000..d84ac4e --- /dev/null +++ b/grafana/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 grafana with context %} + +grafana-package-repo-clean-pkgrepo-absent: + pkgrepo.absent: + - name: {{ grafana.pkg.repo.name }} diff --git a/grafana/package/repo/init.sls b/grafana/package/repo/init.sls new file mode 100644 index 0000000..d3e5518 --- /dev/null +++ b/grafana/package/repo/init.sls @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +include: + - .install diff --git a/grafana/package/repo/install.sls b/grafana/package/repo/install.sls new file mode 100644 index 0000000..d53fdbb --- /dev/null +++ b/grafana/package/repo/install.sls @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import grafana with context %} + + {%- if grafana.pkg.use_upstream_repo %} + {%- from tplroot ~ "/jinja/macros.jinja" import format_kwargs with context %} + +grafana-package-repo-install-pkgrepo-managed: + pkgrepo.managed: + {{- format_kwargs(grafana.pkg.repo) }} + + {%- endif %} diff --git a/pillar.example b/pillar.example index b7f4f79..f204f64 100644 --- a/pillar.example +++ b/pillar.example @@ -2,12 +2,15 @@ # vim: ft=yaml --- grafana: - pkg: grafana - pkgrepo: - humanname: grafana_official - name: deb https://packages.grafana.com/oss/deb stable main - file: /etc/apt/sources.list.d/grafana.list - key_url: https://packages.grafana.com/gpg.key + pkg: + name: grafana + repo: + humanname: grafana_official + name: deb https://packages.grafana.com/oss/deb stable main + file: /etc/apt/sources.list.d/grafana.list + key_url: https://packages.grafana.com/gpg.key + + config_file: /etc/grafana/grafana.ini service: name: grafana-server