Initial role setup with basic configuration

This commit is contained in:
Gregory Ballantine
2026-04-08 11:22:12 -04:00
parent 5a46b4087f
commit dd0ebf4a43
8 changed files with 90 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
Copyright (c) 2026 greg
Copyright (c) 2026 Gregory Ballantine
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

12
defaults/main.yml Normal file
View File

@@ -0,0 +1,12 @@
---
# defaults/main.yml
haproxy_backend_servers:
- name: web01
address: 192.168.1.10
port: 80
- name: web02
address: 192.168.1.11
port: 80
haproxy_backend_balance: roundrobin

6
handlers/main.yml Normal file
View File

@@ -0,0 +1,6 @@
---
- name: reload haproxy
service:
name: "{{ haproxy_service_name }}"
state: reloaded

31
tasks/main.yml Normal file
View File

@@ -0,0 +1,31 @@
---
- name: Load OS-specific variables
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_os_family }}.yml"
- "default.yml"
- name: Install HAProxy
package:
name: "{{ haproxy_package }}"
state: present
- name: Ensure configuration directory exists
file:
path: "{{ haproxy_config_path | dirname }}"
state: directory
mode: '0755'
- name: Deploy HAProxy configuration
template:
src: haproxy.cfg.j2
dest: "{{ haproxy_config_path }}"
validate: "haproxy -c -f %s"
notify: reload haproxy
- name: Ensure HAProxy is started and enabled
service:
name: "{{ haproxy_service_name }}"
state: started
enabled: yes

View File

@@ -0,0 +1,25 @@
global
log /dev/log local0
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
user haproxy
group haproxy
daemon
defaults
log global
mode http
option httplog
timeout connect 5000
timeout client 50000
timeout server 50000
frontend http_front
bind *:80
default_backend http_back
backend http_back
balance {{ haproxy_backend_balance }}
{% for server in haproxy_backend_servers %}
server {{ server.name }} {{ server.address }}:{{ server.port | default(80) }} check
{% endfor %}

5
vars/Debian.yml Normal file
View File

@@ -0,0 +1,5 @@
---
haproxy_package: haproxy
haproxy_config_path: /etc/haproxy/haproxy.cfg
haproxy_service_name: haproxy

5
vars/FreeBSD.yml Normal file
View File

@@ -0,0 +1,5 @@
---
haproxy_package: haproxy
haproxy_config_path: /usr/local/etc/haproxy.conf
haproxy_service_name: haproxy

5
vars/RedHat.yml Normal file
View File

@@ -0,0 +1,5 @@
---
haproxy_package: haproxy
haproxy_config_path: /etc/haproxy/haproxy.cfg
haproxy_service_name: haproxy