From cb3aa80c62d448c21f1334c07e02d0c56a87f765 Mon Sep 17 00:00:00 2001 From: Brian Jackson Date: Mon, 16 Mar 2015 23:39:32 -0500 Subject: [PATCH] Don't overwrite salt variable Using a variable named salt is a bad idea when salt already has a variable named salt. --- salt/api.sls | 8 +-- salt/cloud.sls | 16 ++---- salt/defaults.yaml | 12 ++++ salt/map.jinja | 135 +++++++++++++++++++++++--------------------- salt/master.sls | 8 +-- salt/minion.sls | 8 +-- salt/ssh.sls | 6 +- salt/standalone.sls | 8 +-- salt/syndic.sls | 8 +-- 9 files changed, 111 insertions(+), 98 deletions(-) create mode 100644 salt/defaults.yaml diff --git a/salt/api.sls b/salt/api.sls index 78e5ed1..fde268b 100644 --- a/salt/api.sls +++ b/salt/api.sls @@ -1,14 +1,14 @@ -{% from "salt/map.jinja" import salt with context %} +{% from "salt/map.jinja" import salt_settings with context %} include: - salt.master salt-api: pkg.installed: - - name: {{ salt['salt-api'] }} + - name: {{ salt_settings.salt_api }} service.running: - - name: {{ salt.get('api-service', 'salt-api') }} + - name: {{ salt_settings.api_service }} - require: - - service: {{ salt.get('api-service', 'salt-master') }} + - service: {{ salt_settings.api_service }} - watch: - pkg: salt-master diff --git a/salt/cloud.sls b/salt/cloud.sls index 361df4d..2998a06 100644 --- a/salt/cloud.sls +++ b/salt/cloud.sls @@ -1,6 +1,4 @@ -{% from "salt/map.jinja" import salt with context %} -{% do salt.update(pillar.get('salt', {})) -%} -{% set cloud = salt.get('cloud', {}) -%} +{% from "salt/map.jinja" import salt_settings with context %} python-pip: pkg.installed @@ -24,7 +22,7 @@ apache-libcloud: salt-cloud: pkg.installed: - - name: {{ salt['salt-cloud'] }} + - name: {{ salt_settings.salt_cloud }} - require: - pip: apache-libcloud - pip: pycrypto @@ -32,7 +30,7 @@ salt-cloud: - pip: crypto {% endif %} -{% for folder in cloud['folders'] %} +{% for folder in salt_settings.cloud.folders %} {{ folder }}: file.directory: - name: /etc/salt/{{ folder }} @@ -43,7 +41,7 @@ salt-cloud: - makedirs: True {% endfor %} -{% for cert in pillar.get('salt_cloud_certs', {}) %} +{% for cert in salt_settings.salt_cloud_certs %} {% for type in ['pem'] %} cloud-cert-{{ cert }}-pem: file.managed: @@ -59,23 +57,19 @@ cloud-cert-{{ cert }}-pem: {% endfor %} {% endfor %} -{% for providers in cloud['providers'] %} +{% for providers in salt_settings.cloud.providers %} salt-cloud-profiles-{{ providers }}: file.managed: - name: /etc/salt/cloud.profiles.d/{{ providers }}.conf - template: jinja - source: salt://salt/files/cloud.profiles.d/{{ providers }}.conf -{% endfor %} -{% for providers in cloud['providers'] %} salt-cloud-providers-{{ providers }}: file.managed: - name: /etc/salt/cloud.providers.d/{{ providers }}.conf - template: jinja - source: salt://salt/files/cloud.providers.d/{{ providers }}.conf -{% endfor %} -{% for providers in cloud['providers'] %} salt-cloud-maps-{{ providers }}: file.managed: - name: /etc/salt/cloud.maps.d/{{ providers }}.conf diff --git a/salt/defaults.yaml b/salt/defaults.yaml new file mode 100644 index 0000000..5b9b92f --- /dev/null +++ b/salt/defaults.yaml @@ -0,0 +1,12 @@ +salt: + config_path: /etc/salt + minion_service: salt-minion + master_service: salt-master + api_service: salt-api + syndic_service: salt-syndic + salt_master: salt-master + salt_minion: salt-minion + salt_syndic: salt-syndic + salt_cloud: salt-cloud + salt_api: salt-api + salt_ssh: salt-ssh diff --git a/salt/map.jinja b/salt/map.jinja index a4ada55..0f989e7 100644 --- a/salt/map.jinja +++ b/salt/map.jinja @@ -1,65 +1,72 @@ -{% set salt = salt['grains.filter_by']({ - 'Debian': {'salt-master': 'salt-master', - 'salt-minion': 'salt-minion', - 'salt-syndic': 'salt-syndic', - 'salt-cloud': 'salt-cloud', - 'salt-api': 'salt-api', - 'salt-ssh': 'salt-ssh'}, - 'Ubuntu': {'salt-master': 'salt-master', - 'salt-minion': 'salt-minion', - 'salt-syndic': 'salt-syndic', - 'salt-cloud': 'salt-cloud', - 'salt-api': 'salt-api', - 'salt-ssh': 'salt-ssh'}, - 'CentOS': {'salt-master': 'salt-master', - 'salt-minion': 'salt-minion', - 'salt-syndic': 'salt-syndic', - 'salt-cloud': 'salt-cloud', - 'salt-api': 'salt-api', - 'salt-ssh': 'salt-ssh'}, - 'Amazon': {'salt-master': 'salt-master', - 'salt-minion': 'salt-minion', - 'salt-syndic': 'salt-syndic', - 'salt-cloud': 'salt-cloud', - 'salt-api': 'salt-api', - 'salt-ssh': 'salt-ssh'}, - 'Fedora': {'salt-master': 'salt-master', - 'salt-minion': 'salt-minion', - 'salt-syndic': 'salt-syndic', - 'salt-cloud': 'salt-cloud', - 'salt-api': 'salt-api', - 'salt-ssh': 'salt-ssh'}, - 'RedHat': {'salt-master': 'salt-master', - 'salt-minion': 'salt-minion', - 'salt-syndic': 'salt-syndic', - 'salt-cloud': 'salt-cloud', - 'salt-api': 'salt-api', - 'salt-ssh': 'salt-ssh'}, - 'Gentoo': {'salt-master': 'app-admin/salt', - 'salt-minion': 'app-admin/salt', - 'salt-syndic': 'app-admin/salt', - 'salt-api': 'app-admin/salt', - 'salt-cloud': 'app-admin/salt'}, - 'Arch': {'salt-master': 'salt-zmq', - 'salt-minion': 'salt-zmq', - 'salt-syndic': 'salt-zmq', - 'salt-cloud': 'salt-zmq', - 'salt-api': 'salt-zmq', - 'salt-ssh': 'salt-zmq'}, - 'Suse': {'salt-master': 'salt-master', - 'salt-minion': 'salt-minion', - 'salt-syndic': 'salt-syndic', - 'salt-api': 'salt-api', - 'salt-cloud': 'salt-cloud', - 'salt-ssh': 'salt-ssh'}, - 'FreeBSD': {'salt-master': 'py27-salt', - 'salt-minion': 'py27-salt', - 'salt-syndic': 'py27-salt', - 'salt-cloud': 'py27-salt', - 'salt-api': 'py27-salt', - 'config-path': '/usr/local/etc/salt', - 'minion-service': 'salt_minion', - 'master-service': 'salt_master', - 'api-service': 'salt_api', - 'syndic-service': 'salt_syndic'}, +{% import_yaml "salt/defaults.yaml" as default_settings %} + +{% set distro_map = salt['grains.filter_by']({ + 'Debian': {'salt_master': 'salt-master', + 'salt_minion': 'salt-minion', + 'salt_syndic': 'salt-syndic', + 'salt_cloud': 'salt-cloud', + 'salt_api': 'salt-api', + 'salt_ssh': 'salt-ssh'}, + 'Ubuntu': {'salt_master': 'salt-master', + 'salt_minion': 'salt-minion', + 'salt_syndic': 'salt-syndic', + 'salt_cloud': 'salt-cloud', + 'salt_api': 'salt-api', + 'salt_ssh': 'salt-ssh'}, + 'CentOS': {'salt_master': 'salt-master', + 'salt_minion': 'salt-minion', + 'salt_syndic': 'salt-syndic', + 'salt_cloud': 'salt-cloud', + 'salt_api': 'salt-api', + 'salt_ssh': 'salt-ssh'}, + 'Amazon': {'salt_master': 'salt-master', + 'salt_minion': 'salt-minion', + 'salt_syndic': 'salt-syndic', + 'salt_cloud': 'salt-cloud', + 'salt_api': 'salt-api', + 'salt_ssh': 'salt-ssh'}, + 'Fedora': {'salt_master': 'salt-master', + 'salt_minion': 'salt-minion', + 'salt_syndic': 'salt-syndic', + 'salt_cloud': 'salt-cloud', + 'salt_api': 'salt-api', + 'salt_ssh': 'salt-ssh'}, + 'RedHat': {'salt_master': 'salt-master', + 'salt_minion': 'salt-minion', + 'salt_syndic': 'salt-syndic', + 'salt_cloud': 'salt-cloud', + 'salt_api': 'salt-api', + 'salt_ssh': 'salt-ssh'}, + 'Gentoo': {'salt_master': 'app-admin/salt', + 'salt_minion': 'app-admin/salt', + 'salt_syndic': 'app-admin/salt', + 'salt_api': 'app-admin/salt', + 'salt_cloud': 'app-admin/salt'}, + 'Arch': {'salt_master': 'salt-zmq', + 'salt_minion': 'salt-zmq', + 'salt_syndic': 'salt-zmq', + 'salt_cloud': 'salt-zmq', + 'salt_api': 'salt-zmq', + 'salt_ssh': 'salt-zmq'}, + 'Suse': {'salt_master': 'salt-master', + 'salt_minion': 'salt-minion', + 'salt_syndic': 'salt-syndic', + 'salt_api': 'salt-api', + 'salt_cloud': 'salt-cloud', + 'salt_ssh': 'salt-ssh'}, + 'FreeBSD': {'salt_master': 'py27-salt', + 'salt_minion': 'py27-salt', + 'salt_syndic': 'py27-salt', + 'salt_cloud': 'py27-salt', + 'salt_api': 'py27-salt', + 'config_path': '/usr/local/etc/salt', + 'minion_service': 'salt_minion', + 'master_service': 'salt_master', + 'api_service': 'salt_api', + 'syndic_service': 'salt_syndic'}, }, merge=salt['pillar.get']('salt:lookup')) %} + +{% do default_settings.salt.update(distro_map) %} + +{% set salt_settings = salt['pillar.get']('salt', default=default_settings.salt, + merge=True) %} diff --git a/salt/master.sls b/salt/master.sls index 8885a0a..49b6ef0 100644 --- a/salt/master.sls +++ b/salt/master.sls @@ -1,16 +1,16 @@ -{% from "salt/map.jinja" import salt with context %} +{% from "salt/map.jinja" import salt_settings with context %} salt-master: pkg.installed: - - name: {{ salt['salt-master'] }} + - name: {{ salt_settings.salt_master }} file.recurse: - - name: {{ salt.get('config-path', '/etc/salt') }}/master.d + - name: {{ salt_settings.config_path }}/master.d - template: jinja - source: salt://salt/files/master.d - clean: True service.running: - enable: True - - name: {{ salt.get('master-service', 'salt-master') }} + - name: {{ salt_settings.master_service }} - watch: - pkg: salt-master - file: salt-master diff --git a/salt/minion.sls b/salt/minion.sls index db4958b..bf0860a 100644 --- a/salt/minion.sls +++ b/salt/minion.sls @@ -1,10 +1,10 @@ -{% from "salt/map.jinja" import salt with context %} +{% from "salt/map.jinja" import salt_settings with context %} salt-minion: pkg.installed: - - name: {{ salt['salt-minion'] }} + - name: {{ salt_settings.salt_minion }} file.recurse: - - name: {{ salt.get('config-path', '/etc/salt') }}/minion.d + - name: {{ salt_settings.config_path }}/minion.d - template: jinja - source: salt://salt/files/minion.d - clean: True @@ -12,7 +12,7 @@ salt-minion: standalone: False service.running: - enable: True - - name: {{ salt.get('minion-service', 'salt-minion') }} + - name: {{ salt_settings.minion_service }} - watch: - pkg: salt-minion - file: salt-minion diff --git a/salt/ssh.sls b/salt/ssh.sls index 411d57f..1a43ab9 100644 --- a/salt/ssh.sls +++ b/salt/ssh.sls @@ -1,12 +1,12 @@ -{% from "salt/map.jinja" import salt with context %} +{% from "salt/map.jinja" import salt_settings with context %} ensure salt-ssh is installed: pkg.installed: - - name: {{ salt['salt-ssh'] }} + - name: {{ salt_settings.salt_ssh }} ensure roster config: file.managed: - - name: {{ salt.get('config_path', '/etc/salt') }}/roster + - name: {{ salt_settings.config_path }}/roster - source: salt://salt/files/roster.jinja - template: jinja - require: diff --git a/salt/standalone.sls b/salt/standalone.sls index aaa2007..d7bf2d8 100644 --- a/salt/standalone.sls +++ b/salt/standalone.sls @@ -1,10 +1,10 @@ -{% from "salt/map.jinja" import salt with context %} +{% from "salt/map.jinja" import salt_settings with context %} salt-minion: pkg.installed: - - name: {{ salt['salt-minion'] }} + - name: {{ salt_settings.salt_minion }} file.recurse: - - name: {{ salt.get('config-path', '/etc/salt') }}/minion.d + - name: {{ salt_settings.config_path }}/minion.d - template: jinja - source: salt://salt/files/minion.d - clean: True @@ -12,7 +12,7 @@ salt-minion: standalone: True service.dead: - enable: False - - name: {{ salt.get('minion-service', 'salt-minion') }} + - name: {{ salt_settings.minion_service }} - require: - pkg: salt-minion - file: salt-minion diff --git a/salt/syndic.sls b/salt/syndic.sls index a9ec986..65c67e2 100644 --- a/salt/syndic.sls +++ b/salt/syndic.sls @@ -1,15 +1,15 @@ -{% from "salt/map.jinja" import salt with context %} +{% from "salt/map.jinja" import salt_settings with context %} include: - salt.master salt-syndic: pkg.installed: - - name: {{ salt['salt-syndic'] }} + - name: {{ salt_settings.salt_syndic }} service: - running - require: - - service: {{ salt.get('syndic-service', 'salt-master') }} + - service: {{ salt_settings.syndic_service }} - watch: - pkg: salt-master - - file: {{ salt.get('config-path', '/etc/salt') }}/master + - file: {{ salt_settings.config_path }}/master