Configured haproxies
This commit is contained in:
34
roles/haproxy/tasks/main.yml
Normal file
34
roles/haproxy/tasks/main.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
- name: Install haproxy
|
||||
command: >
|
||||
bash -c "apt-get update -qq
|
||||
apt-get install -y -qq haproxy"
|
||||
become: true
|
||||
|
||||
- name: Copy haproxy config
|
||||
template:
|
||||
src: ../roles/haproxy/templates/haproxy.cfg.j2
|
||||
dest: /etc/haproxy/haproxy.cfg
|
||||
register: haproxy_cfg
|
||||
become: true
|
||||
|
||||
- name: Set haproxy.cfg permissions
|
||||
file:
|
||||
path: /etc/haproxy/haproxy.cfg
|
||||
mode: 0644
|
||||
become: true
|
||||
|
||||
- name: Set haproxy as enabled
|
||||
lineinfile:
|
||||
path: /etc/default/haproxy
|
||||
regexp: '^ENABLED='
|
||||
line: 'ENABLED=1'
|
||||
become: true
|
||||
|
||||
- name: Restart haproxy if /etc/haproxy/haproxy.cfg or /etc/default/haproxy changes.
|
||||
service:
|
||||
name: haproxy
|
||||
state: restarted
|
||||
when: haproxy_cfg.changed
|
||||
become: true
|
||||
|
||||
53
roles/haproxy/templates/haproxy.cfg.j2
Normal file
53
roles/haproxy/templates/haproxy.cfg.j2
Normal file
@@ -0,0 +1,53 @@
|
||||
global
|
||||
chroot /var/lib/haproxy
|
||||
daemon
|
||||
group haproxy
|
||||
log 127.0.0.1 local2
|
||||
maxconn 21000
|
||||
pidfile /run/haproxy.pid
|
||||
user haproxy
|
||||
|
||||
defaults
|
||||
log global
|
||||
mode http
|
||||
timeout connect 5000ms
|
||||
timeout client 240000ms
|
||||
timeout server 240000ms
|
||||
timeout check 10000ms
|
||||
|
||||
listen stats
|
||||
bind *:2016
|
||||
mode http
|
||||
stats enable
|
||||
stats uri /haproxy
|
||||
stats hide-version
|
||||
stats refresh 5s
|
||||
stats realm Haproxy\ Statistics
|
||||
|
||||
listen http
|
||||
bind *:80
|
||||
mode tcp
|
||||
balance roundrobin
|
||||
{% for node in groups['swarm-bootstrap'] %}
|
||||
server {{node}} {{ hostvars[node]['ansible_host'] }}:80 check fall 3 inter 3s rise 2
|
||||
{% endfor %}
|
||||
{% for node in groups['swarm-managers'] %}
|
||||
server {{node}} {{ hostvars[node]['ansible_host'] }}:80 check fall 3 inter 3s rise 2
|
||||
{% endfor %}
|
||||
{% for node in groups['swarm-workers'] %}
|
||||
server {{node}} {{ hostvars[node]['ansible_host'] }}:80 check fall 3 inter 3s rise 2
|
||||
{% endfor %}
|
||||
|
||||
listen https
|
||||
bind *:443
|
||||
mode tcp
|
||||
balance roundrobin
|
||||
{% for node in groups['swarm-bootstrap'] %}
|
||||
server {{node}} {{ hostvars[node]['ansible_host'] }}:443 check fall 3 inter 3s rise 2
|
||||
{% endfor %}
|
||||
{% for node in groups['swarm-managers'] %}
|
||||
server {{node}} {{ hostvars[node]['ansible_host'] }}:443 check fall 3 inter 3s rise 2
|
||||
{% endfor %}
|
||||
{% for node in groups['swarm-workers'] %}
|
||||
server {{node}} {{ hostvars[node]['ansible_host'] }}:443 check fall 3 inter 3s rise 2
|
||||
{% endfor %}
|
||||
Reference in New Issue
Block a user