Ansible playbook that provisions a group of servers to run HAProxy with a shared hosting IP from keepalived.
Find a file
2024-08-01 13:01:35 -06:00
collections Adding requirement 2022-08-27 07:48:55 -06:00
roles/haproxy Adding packages tag 2024-08-01 13:01:35 -06:00
haproxy.yml Moving become flag to the role level 2022-08-25 16:19:08 -06:00
hosts.yml Adding certbot syncing 2022-08-30 13:07:12 -06:00
LICENSE Initial commit 2021-09-23 09:52:51 -06:00
README.md Adding option for authentication 2022-08-23 09:29:21 -06:00
site.yml Initial commit 2021-09-23 09:54:34 -06:00

Ansible-HAProxy-Failover

Ansible playbook that provisions a group of servers to run HAProxy with a shared hosting IP from keepalived.

Variables

Variable Required Default Choices Description
haproxy_bind_adapter Yes eth0 Interface to use for the Shared IP
haproxy_config_file Yes example.haproxy.cfg.j2 File name to use for the haproxy config file
haproxy_keepalived_adapter Yes eth0 Interface to use for the keepalived communication
haproxy_keepalived_adapter_vlan No When specified, this will setup the given vlan and use that for the keepalived communication to keep the traffic out of the primary network
haproxy_keepalived_ip Yes 172.16.10.1/24 IP to use for the keepalived communication
haproxy_keepalived_process_weight Yes 10 Weight used for tracking the haproxy process on the server
haproxy_listen_ports Yes 22/tcp, 80/tcp, 443/tcp, 9999/tcp The firewall ports/protocols that should be opened on the firewall
haproxy_shared_ip Yes Shared IP that will be used by the group
haproxy_shared_ip_subnet Yes /24 Subnet for the shared IP
haproxy_shared_password No Optional password that should be used for the keepalived authentication
haproxy_shared_priority Yes 100 Keepalived priority for the host - this will
haproxy_shared_state Yes MASTER MASTER/BACKUP What state the keepalived configuration will start with for the desired host - After config starts it will determine if other members exist and adjust based on priority
haproxy_shared_virtual_router_id Yes 25 Virtual Router ID for the keepalived configuration - This should be the same for the group

Example

Execute playbook with needed variables

ansible-playbook -i hosts site.yml --ask-pass --ask-become-pass

Inventory File:

---
# file: hosts

haproxy:
  hosts:
    dev-ha01:
      ansible_host: 10.1.1.3
      haproxy_shared_state: MASTER
      haproxy_shared_priority: 101
      haproxy_bind_adapter: "eth0"
      haproxy_keepalived_adapter: "eth0"
      haproxy_keepalived_adapter_vlan: "100"
      haproxy_keepalived_ip: 172.16.10.1/24
    
    dev-ha02:
      ansible_host: 10.1.1.4
      haproxy_shared_state: BACKUP
      haproxy_shared_priority: 100
      haproxy_bind_adapter: "eth0"
      haproxy_keepalived_adapter: "eth0"
      haproxy_keepalived_adapter_vlan: "100"
      haproxy_keepalived_ip: 172.16.10.2/24

    dev-ha03:
      ansible_host: 10.1.1.5
      haproxy_shared_state: BACKUP
      haproxy_shared_priority: 99
      haproxy_bind_adapter: "eth0"
      haproxy_keepalived_adapter: "eth0"
      haproxy_keepalived_adapter_vlan: "100"
      haproxy_keepalived_ip: 172.16.10.3/24

  vars:
    haproxy_shared_ip: "10.10.2.60"
    haproxy_shared_ip_subnet: "/24"
    haproxy_shared_virtual_router_id: 25
    

License

See LICENSE file for full license information.