From 2b83ca08609ffe8a5e090f8729c3bde313821bed Mon Sep 17 00:00:00 2001 From: Eric Veiras Galisson Date: Tue, 31 Oct 2017 14:09:52 +0100 Subject: [PATCH 1/3] refactoring code to use map.jinja for config values at the moment only Debian managed, FreeBSD exception still in state --- haproxy/config.sls | 13 ++++++++----- haproxy/install.sls | 4 +++- haproxy/map.jinja | 11 +++++++++++ haproxy/service.sls | 4 +++- 4 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 haproxy/map.jinja diff --git a/haproxy/config.sls b/haproxy/config.sls index e8c9865..21cc8fc 100644 --- a/haproxy/config.sls +++ b/haproxy/config.sls @@ -1,13 +1,16 @@ +{% from "haproxy/map.jinja" import haproxy with context %} + +{% set config_file = salt['pillar.get']('haproxy:config_file_path', haproxy.config_file) %} haproxy.config: file.managed: - - name: {{ salt['pillar.get']('haproxy:config_file_path', '/etc/haproxy/haproxy.cfg') }} - - source: salt://haproxy/templates/haproxy.jinja + - name: {{ config_file }} + - source: {{ haproxy.config_file_source }} - template: jinja - - user: root + - user: {{ haproxy.user }} {% if salt['grains.get']('os_family') == 'FreeBSD' %} - group: wheel {% else %} - - group: root + - group: {{ haproxy.group }} {% endif %} - mode: 644 - require_in: @@ -16,5 +19,5 @@ haproxy.config: - service: haproxy.service {% if salt['pillar.get']('haproxy:overwrite', default=True) == False %} - unless: - - test -e {{ salt['pillar.get']('haproxy:config_file_path', '/etc/haproxy/haproxy.cfg') }} + - test -e {{ config_file }} {% endif %} diff --git a/haproxy/install.sls b/haproxy/install.sls index 736320f..2a971fa 100644 --- a/haproxy/install.sls +++ b/haproxy/install.sls @@ -1,6 +1,8 @@ +{% from "haproxy/map.jinja" import haproxy with context %} + haproxy.install: pkg.installed: - - name: haproxy + - name: {{ haproxy.package }} {% if salt['pillar.get']('haproxy:require') %} - require: {% for item in salt['pillar.get']('haproxy:require') %} diff --git a/haproxy/map.jinja b/haproxy/map.jinja new file mode 100644 index 0000000..ae71ad5 --- /dev/null +++ b/haproxy/map.jinja @@ -0,0 +1,11 @@ +{% set haproxy = salt['grains.filter_by']({ + 'Debian': { + 'package': 'haproxy', + 'config_file': '/etc/haproxy/haproxy.cfg', + 'config_file_source': 'salt://haproxy/templates/haproxy.jinja', + 'user': 'root', + 'group': 'root', + 'service': 'haproxy', + }, +}, merge=salt['pillar.get']('haproxy:lookup')) %} + diff --git a/haproxy/service.sls b/haproxy/service.sls index 21c8434..6883315 100644 --- a/haproxy/service.sls +++ b/haproxy/service.sls @@ -1,7 +1,9 @@ +{% from "haproxy/map.jinja" import haproxy with context %} + haproxy.service: {% if salt['pillar.get']('haproxy:enable', True) %} service.running: - - name: haproxy + - name: {{ haproxy.service }} - enable: True - reload: True - require: From 752c3e56414ae84e0d7d63eb9e2c5905154323b4 Mon Sep 17 00:00:00 2001 From: Eric Veiras Galisson Date: Tue, 31 Oct 2017 14:23:53 +0100 Subject: [PATCH 2/3] moving specific FreeBSD code to map.jinja, updating pillar.example --- haproxy/config.sls | 3 --- haproxy/map.jinja | 7 +++++-- pillar.example | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/haproxy/config.sls b/haproxy/config.sls index 21cc8fc..71e3d83 100644 --- a/haproxy/config.sls +++ b/haproxy/config.sls @@ -7,9 +7,6 @@ haproxy.config: - source: {{ haproxy.config_file_source }} - template: jinja - user: {{ haproxy.user }} - {% if salt['grains.get']('os_family') == 'FreeBSD' %} - - group: wheel - {% else %} - group: {{ haproxy.group }} {% endif %} - mode: 644 diff --git a/haproxy/map.jinja b/haproxy/map.jinja index ae71ad5..158ef5c 100644 --- a/haproxy/map.jinja +++ b/haproxy/map.jinja @@ -1,5 +1,5 @@ {% set haproxy = salt['grains.filter_by']({ - 'Debian': { + 'default': { 'package': 'haproxy', 'config_file': '/etc/haproxy/haproxy.cfg', 'config_file_source': 'salt://haproxy/templates/haproxy.jinja', @@ -7,5 +7,8 @@ 'group': 'root', 'service': 'haproxy', }, -}, merge=salt['pillar.get']('haproxy:lookup')) %} + 'FreeBSD': { + 'group': 'wheel', + }, +}, merge=salt['pillar.get']('haproxy:lookup'), base='default') %} diff --git a/pillar.example b/pillar.example index ef8fcf9..f49824b 100644 --- a/pillar.example +++ b/pillar.example @@ -3,6 +3,10 @@ # haproxy: + # use lookup section to override 'map.jinja' values + #lookup: + #user: 'custom-user' + #group: 'custom-group' enabled: True overwrite: True # Overwrite an existing config file if present (default behaviour unless set to false) config_file_path: /etc/haproxy/haproxy.cfg From 6493d24ad3862abb6bba79251fc3417ce3b25982 Mon Sep 17 00:00:00 2001 From: Eric Veiras Galisson Date: Thu, 2 Nov 2017 09:40:52 +0100 Subject: [PATCH 3/3] info in pillar.example about old and new setting for conf file path --- haproxy/config.sls | 1 - pillar.example | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/haproxy/config.sls b/haproxy/config.sls index 71e3d83..b70f570 100644 --- a/haproxy/config.sls +++ b/haproxy/config.sls @@ -8,7 +8,6 @@ haproxy.config: - template: jinja - user: {{ haproxy.user }} - group: {{ haproxy.group }} - {% endif %} - mode: 644 - require_in: - service: haproxy.service diff --git a/pillar.example b/pillar.example index f49824b..a83917e 100644 --- a/pillar.example +++ b/pillar.example @@ -7,9 +7,12 @@ haproxy: #lookup: #user: 'custom-user' #group: 'custom-group' + # new setting to override configuration file path + #config_file: /etc/haproxy/haproxy.cfg enabled: True 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: log: - 127.0.0.1 local2