Configured haproxies

This commit is contained in:
2019-04-08 10:53:13 -04:00
parent a5e3dbd8ba
commit 98810165e0
9 changed files with 204 additions and 14 deletions

View File

@@ -0,0 +1,3 @@
---
vip_interface: ens18
vip_address: 10.0.0.200

View File

@@ -0,0 +1,27 @@
---
- name: Install keepalived
command: >
bash -c "apt-get update
apt-get install -y keepalived"
become: true
- name: Copy keepalived haproxy script
template:
src: ../templates/keepalived_haproxy.j2
dest: /usr/local/bin/keepalived_haproxy
mode: a+x
become: true
- name: Write Keepalived Config
template:
src: ../templates/keepalived.conf.j2
dest: /etc/keepalived/keepalived.conf
mode: a+x
become: true
- name: Ensure Keepalived enabled and running
service:
name: keepalived
state: restarted
enabled: true
become: true

View File

@@ -0,0 +1,40 @@
global_defs {
router_id HOME-PROXY.WIMER.HOME
}
vrrp_script check_vip {
script "curl http://localhost:2016/haproxy"
interval 2
weight -100
}
vrrp_instance HAPROXY_API_FRONT {
{% if play_hosts|first == inventory_hostname %}
state MASTER
priority 150
{% else %}
state BACKUP
priority 100
{% endif %}
interface {{ vip_interface }}
virtual_router_id {{ vip_address.split('.')[3] }}
advert_int 1
authentication {
auth_type PASS
auth_pass home
}
dont_track_primary
track_script {
check_vip
}
virtual_ipaddress {
{{ vip_address }} dev {{ vip_interface }}
}
notify /usr/local/bin/keepalived_haproxy
smtp_alert
}

View File

@@ -0,0 +1,20 @@
#!/bin/bash
TYPE=${1}
NAME=${2}
STATE=${3}
case ${STATE} in
"MASTER") service haproxy start
exit 0
;;
"BACKUP") service haproxy start
exit 0
;;
"FAULT") service haproxy stop
exit 0
;;
*) echo "unknown state"
exit 1
;;
esac