Merge pull request #69 from daks/map.jinja

Switching to map.jinja to define platform specific values
This commit is contained in:
N 2017-12-13 22:30:14 +00:00 committed by GitHub
commit 1cbdd4cb79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 12 deletions

View file

@ -1,14 +1,13 @@
{% from "haproxy/map.jinja" import haproxy with context %}
{% set config_file = salt['pillar.get']('haproxy:config_file_path', haproxy.config_file) %}
haproxy.config: haproxy.config:
file.managed: file.managed:
- name: {{ salt['pillar.get']('haproxy:config_file_path', '/etc/haproxy/haproxy.cfg') }} - name: {{ config_file }}
- source: salt://haproxy/templates/haproxy.jinja - source: {{ haproxy.config_file_source }}
- template: jinja - template: jinja
- user: root - user: {{ haproxy.user }}
{% if salt['grains.get']('os_family') == 'FreeBSD' %} - group: {{ haproxy.group }}
- group: wheel
{% else %}
- group: root
{% endif %}
- mode: 644 - mode: 644
- require_in: - require_in:
- service: haproxy.service - service: haproxy.service
@ -16,5 +15,5 @@ haproxy.config:
- service: haproxy.service - service: haproxy.service
{% if salt['pillar.get']('haproxy:overwrite', default=True) == False %} {% if salt['pillar.get']('haproxy:overwrite', default=True) == False %}
- unless: - unless:
- test -e {{ salt['pillar.get']('haproxy:config_file_path', '/etc/haproxy/haproxy.cfg') }} - test -e {{ config_file }}
{% endif %} {% endif %}

View file

@ -1,6 +1,8 @@
{% from "haproxy/map.jinja" import haproxy with context %}
haproxy.install: haproxy.install:
pkg.installed: pkg.installed:
- name: haproxy - name: {{ haproxy.package }}
{% if salt['pillar.get']('haproxy:require') %} {% if salt['pillar.get']('haproxy:require') %}
- require: - require:
{% for item in salt['pillar.get']('haproxy:require') %} {% for item in salt['pillar.get']('haproxy:require') %}

14
haproxy/map.jinja Normal file
View file

@ -0,0 +1,14 @@
{% set haproxy = salt['grains.filter_by']({
'default': {
'package': 'haproxy',
'config_file': '/etc/haproxy/haproxy.cfg',
'config_file_source': 'salt://haproxy/templates/haproxy.jinja',
'user': 'root',
'group': 'root',
'service': 'haproxy',
},
'FreeBSD': {
'group': 'wheel',
},
}, merge=salt['pillar.get']('haproxy:lookup'), base='default') %}

View file

@ -1,7 +1,9 @@
{% from "haproxy/map.jinja" import haproxy with context %}
haproxy.service: haproxy.service:
{% if salt['pillar.get']('haproxy:enable', True) %} {% if salt['pillar.get']('haproxy:enable', True) %}
service.running: service.running:
- name: haproxy - name: {{ haproxy.service }}
- enable: True - enable: True
- reload: True - reload: True
- require: - require:

View file

@ -3,9 +3,16 @@
# #
haproxy: haproxy:
# use lookup section to override 'map.jinja' values
#lookup:
#user: 'custom-user'
#group: 'custom-group'
# new setting to override configuration file path
#config_file: /etc/haproxy/haproxy.cfg
enabled: True enabled: True
overwrite: True # Overwrite an existing config file if present (default behaviour unless set to false) overwrite: True # Overwrite an existing config file if present (default behaviour unless set to false)
config_file_path: /etc/haproxy/haproxy.cfg # old setting to override configuration file path, kept for compatibility
#config_file_path: /etc/haproxy/haproxy.cfg
global: global:
log: log:
- 127.0.0.1 local2 - 127.0.0.1 local2