use map
diff --git a/map.jinja b/map.jinja
new file mode 100644
index 0000000..31ca2b9
--- /dev/null
+++ b/map.jinja
@@ -0,0 +1,29 @@
+
+{% set server = salt['grains.filter_by']({
+ 'Arch': {
+ 'pkgs': ['statsd'],
+ 'service': 'statsd',
+ 'config_prefix': '/etc/statsd/',
+ 'service_location': '/etc/init.d/statsd',
+ 'source': 'https://github.com/etsy/statsd.git',
+ 'config': "".join((server.config_prefix,'localConfig.js'),),
+ },
+ 'Debian': {
+ 'pkgs': ['statsd'],
+ 'service': 'statsd',
+ 'config_prefix': '/etc/statsd/',
+ 'service_location': '/etc/init.d/statsd',
+ 'source': 'https://github.com/etsy/statsd.git',
+ 'config': "".join((server.config_prefix,'localConfig.js'),),
+ },
+ 'RedHat': {
+ 'pkgs': ['statsd'],
+ 'service': 'statsd',
+ 'config_prefix': '/etc/statsd/conf.d/',
+ 'config_suffix': '.conf',
+ 'service_location': '/etc/init.d/statsd',
+ 'source': 'https://github.com/etsy/statsd.git',
+ 'config': "".join((server.config_prefix,'localConfig.js'),),
+ }
+}, merge=salt['pillar.get']('statsd:server')) %}
+
diff --git a/server.sls b/server.sls
index 38d23b9..926accb 100755
--- a/server.sls
+++ b/server.sls
@@ -1,4 +1,6 @@
-{%- if pillar.statsd.server.enabled %}
+{% from "statsd/map.jinja" import server with context %}
+
+{%- if server.enabled %}
include:
- nodejs
@@ -10,18 +12,16 @@
- system: True
- home: /srv/statsd
- require:
- - git: https://github.com/etsy/statsd.git
+ - git: {{ server.source }}
- pkg: nodejs_packages
-https://github.com/etsy/statsd.git:
+{{ server.source }}:
git.latest:
- target: /srv/statsd/statsd
- require:
- pkg: git_packages
-{% if grains.os_family == "Debian" %}
-
-/etc/init.d/statsd:
+{{ server.service_location }}:
file.managed:
- source: salt://statsd/conf/init
- user: root
@@ -29,26 +29,27 @@
- mode: 744
- template: jinja
-statsd:
+{% set conf = "".join((server.config_prefix,'localConfig.js'),) %}
+
+{{ server.service }}:
service.running:
- enable: true
- require:
- - file: /etc/init.d/statsd
+ - file: {{ server.service_location }}
- watch:
- - file: /etc/statsd/localConfig.js
+ - file: {{ server.config }}
- cmd: install_statsd_deps
-{% endif %}
-
install_statsd_deps:
cmd.run:
- name: npm install
- cwd: /srv/statsd/statsd/
- unless: test -e /srv/statsd/statsd/node_modules
- require:
- - git: https://github.com/etsy/statsd.git
+ - git: {{ server.source }}
-/etc/statsd/localConfig.js:
+
+{{ server.config }}:
file.managed:
- source: salt://statsd/conf/localConfig.js
- user: root