Merge pull request #10 from sitepoint/various_qa_fixes

Minor improvements
This commit is contained in:
Forrest 2015-07-23 10:28:28 -07:00
commit b83deb4f28
5 changed files with 47 additions and 25 deletions

View file

@ -3,6 +3,11 @@
# Meta-state to fully setup haproxy on debian. (or any other distro that has haproxy in their repo) # Meta-state to fully setup haproxy on debian. (or any other distro that has haproxy in their repo)
include: include:
{% if salt['pillar.get']('haproxy:include') %}
{% for item in salt['pillar.get']('haproxy:include') %}
- {{ item }}
{% endfor %}
{% endif %}
- haproxy.install - haproxy.install
- haproxy.service - haproxy.service
- haproxy.config - haproxy.config

View file

@ -12,3 +12,9 @@ haproxy_ppa_repo:
haproxy.install: haproxy.install:
pkg.installed: pkg.installed:
- name: haproxy - name: haproxy
{% if salt['pillar.get']('haproxy:require') %}
- require:
{% for item in salt['pillar.get']('haproxy:require') %}
- {{ item }}
{% endfor %}
{% endif %}

View file

@ -1,17 +1,26 @@
haproxy.service: haproxy.service:
{% if salt['pillar.get']('haproxy:enable', True) %}
service.running: service.running:
- name: haproxy - name: haproxy
- enable: True - enable: True
- reload: True - reload: True
- require: - require:
- pkg: haproxy - pkg: haproxy
file: haproxy.service
- watch: - watch:
- file: haproxy.config - file: haproxy.config
file.managed: {% else %}
service.dead:
- name: haproxy
- enable: False
{% endif %}
file.replace:
- name: /etc/default/haproxy - name: /etc/default/haproxy
#TODO: Add switch to turn the service on and off based on pillar configuration. {% if salt['pillar.get']('haproxy:enabled', True) %}
- source: salt://haproxy/files/haproxy-init-enable - pattern: ENABLED=0$
- create: True - repl: ENABLED=1
- user: "root" {% else %}
- group: "root" - pattern: ENABLED=1$
- mode: "0644" - repl: ENABLED=0
{% endif %}
- show_changes: True

View file

@ -16,14 +16,15 @@ global
group {{ salt['pillar.get']('haproxy:global:group', 'haproxy') }} group {{ salt['pillar.get']('haproxy:global:group', 'haproxy') }}
{%- if salt['pillar.get']('haproxy:global:chroot:enable', 'no') == True %} {%- if salt['pillar.get']('haproxy:global:chroot:enable', 'no') == True %}
chroot {{ salt['pillar.get']('haproxy:global:chroot:path', '/tmp') }} chroot {{ salt['pillar.get']('haproxy:global:chroot:path', '/tmp') }}
{% endif %} {%- endif %}
{%- if salt['pillar.get']('haproxy:global:daemon', 'no') == True %} {%- if salt['pillar.get']('haproxy:global:daemon', 'no') == True %}
daemon daemon
{% endif %} {%- endif %}
{%- if salt['pillar.get']('haproxy:global:stats:enable', 'no') == True %} {% if salt['pillar.get']('haproxy:global:stats:enable', 'no') == True %}
# Stats support is currently limited to socket mode # Stats support is currently limited to socket mode
stats socket {{ salt['pillar.get']('haproxy:global:stats:socketpath', '/tmp/ha_stats.sock') }} stats socket {{ salt['pillar.get']('haproxy:global:stats:socketpath', '/tmp/ha_stats.sock') }}
{% endif %} {%- endif %}
#------------------ #------------------
# common defaults that all the 'listen' and 'backend' sections will # common defaults that all the 'listen' and 'backend' sections will
@ -48,14 +49,14 @@ defaults
{%- for errorfile in salt['pillar.get']('haproxy:defaults:errorfiles').iteritems() %} {%- for errorfile in salt['pillar.get']('haproxy:defaults:errorfiles').iteritems() %}
errorfile {{ errorfile[0] }} {{ errorfile[1] }} errorfile {{ errorfile[0] }} {{ errorfile[1] }}
{%- endfor %} {%- endfor %}
{% endif %} {%- endif %}
{%- if 'listens' in salt['pillar.get']('haproxy', {}) %}
#------------------ #------------------
# listen instances # listen instances
#------------------ #------------------
{%- if 'listens' in salt['pillar.get']('haproxy', {}) %} {%- for listener in salt['pillar.get']('haproxy:listens', {}).iteritems() %}
{%- for listener in salt['pillar.get']('haproxy:listens', {}).iteritems() %}
listen {{ listener[1].get('name', listener[0]) }} listen {{ listener[1].get('name', listener[0]) }}
{%- if 'bind' in listener[1] %} {%- if 'bind' in listener[1] %}
{%- if listener[1].bind[1] is defined and listener[1].bind[1]|length > 1 %} {%- if listener[1].bind[1] is defined and listener[1].bind[1]|length > 1 %}
@ -123,14 +124,14 @@ listen {{ listener[1].get('name', listener[0]) }}
{%- endfor %} {%- endfor %}
{% endif %} {% endif %}
{%- endfor %} {%- endfor %}
{% endif %} {%- endif %}
{%- if 'frontends' in salt['pillar.get']('haproxy', {}) %}
#------------------ #------------------
# frontend instances # frontend instances
#------------------ #------------------
{%- if 'frontends' in salt['pillar.get']('haproxy', {}) %} {%- for frontend in salt['pillar.get']('haproxy:frontends', {}).iteritems() %}
{%- for frontend in salt['pillar.get']('haproxy:frontends', {}).iteritems() %}
frontend {{ frontend[1].get('name', frontend[0]) }} frontend {{ frontend[1].get('name', frontend[0]) }}
{%- if 'bind' in frontend[1] %} {%- if 'bind' in frontend[1] %}
{%- if frontend[1].bind[1] is defined and frontend[1].bind[1]|length > 1 %} {%- if frontend[1].bind[1] is defined and frontend[1].bind[1]|length > 1 %}
@ -165,16 +166,16 @@ frontend {{ frontend[1].get('name', frontend[0]) }}
{%- for use_backend in frontend[1].use_backends %} {%- for use_backend in frontend[1].use_backends %}
use_backend {{ use_backend }} use_backend {{ use_backend }}
{%- endfor %} {%- endfor %}
{% endif %} {%- endif %}
{%- endfor %} {%- endfor %}
{% endif %} {%- endif %}
{%- if 'backends' in salt['pillar.get']('haproxy', {}) %}
#------------------ #------------------
# backend instances # backend instances
#------------------ #------------------
{%- if 'backends' in salt['pillar.get']('haproxy', {}) %} {%- for backend in salt['pillar.get']('haproxy:backends', {}).iteritems() %}
{%- for backend in salt['pillar.get']('haproxy:backends', {}).iteritems() %}
backend {{ backend[1].get('name',backend[0]) }} backend {{ backend[1].get('name',backend[0]) }}
{%- if 'redirects' in backend[1] %} {%- if 'redirects' in backend[1] %}
{%- for redirect in backend[1].redirects %} {%- for redirect in backend[1].redirects %}
@ -183,7 +184,7 @@ backend {{ backend[1].get('name',backend[0]) }}
{% endif %} {% endif %}
{%- if 'balance' in backend[1] %} {%- if 'balance' in backend[1] %}
balance {{ backend[1].balance }} balance {{ backend[1].balance }}
{% endif %} {%- endif %}
{%- if 'options' in backend[1] %} {%- if 'options' in backend[1] %}
{%- for option in backend[1].options %} {%- for option in backend[1].options %}
option {{ option }} option {{ option }}
@ -203,11 +204,11 @@ backend {{ backend[1].get('name',backend[0]) }}
{% endif %} {% endif %}
{%- if 'defaultserver' in backend[1] %} {%- if 'defaultserver' in backend[1] %}
default-server {%- for option, value in backend[1].defaultserver.iteritems() %} {{ ' '.join((option, value|string, '')) }} {%- endfor %} default-server {%- for option, value in backend[1].defaultserver.iteritems() %} {{ ' '.join((option, value|string, '')) }} {%- endfor %}
{% endif %} {%- endif %}
{%- if 'servers' in backend[1] %} {%- if 'servers' in backend[1] %}
{%- for server in backend[1].servers.iteritems() %} {%- for server in backend[1].servers.iteritems() %}
server {{ server[1].get('name',server[0]) }} {{ server[1].host }}:{{ server[1].port }} {{ server[1].check }} server {{ server[1].get('name',server[0]) }} {{ server[1].host }}:{{ server[1].port }} {{ server[1].check }}
{%- endfor %} {%- endfor %}
{% endif %} {% endif %}
{%- endfor %} {%- endfor %}
{% endif %} {%- endif %}

View file

@ -3,6 +3,7 @@
# #
haproxy: haproxy:
enabled: True
config_file_path: /etc/haproxy/haproxy.cfg config_file_path: /etc/haproxy/haproxy.cfg
global: global:
stats: stats: