Skip to content

Commit

Permalink
feat(repository): support rpm-based linux distros
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the parameter `pkg` is now a dictionary. References
 to `grafana.pkg` should be changed to `grafana.pkg.name`.
  • Loading branch information
noelmcloughlin committed Jun 12, 2019
1 parent e2a9da6 commit ded3157
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 29 deletions.
13 changes: 11 additions & 2 deletions grafana/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down
14 changes: 14 additions & 0 deletions grafana/jinja/macros.jinja
Original file line number Diff line number Diff line change
@@ -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 %}
41 changes: 33 additions & 8 deletions grafana/osfamilymap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}

Expand All @@ -32,7 +55,8 @@ Arch: {}
Alpine: {}

FreeBSD:
pkg: grafana5
pkg:
name: grafana5
config_file: /usr/local/etc/grafana.conf
config:
paths:
Expand All @@ -52,6 +76,7 @@ Solaris: {}
Windows: {}

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

include:
- .install
15 changes: 15 additions & 0 deletions grafana/package/repo/install.sls
Original file line number Diff line number Diff line change
@@ -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 %}
15 changes: 9 additions & 6 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ded3157

Please sign in to comment.