diff --git a/LICENSE b/LICENSE index ad3a9e4..aac2b13 100644 --- a/LICENSE +++ b/LICENSE @@ -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: diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..e46f175 --- /dev/null +++ b/defaults/main.yml @@ -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 \ No newline at end of file diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..bf83833 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,6 @@ +--- + +- name: reload haproxy + service: + name: "{{ haproxy_service_name }}" + state: reloaded diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..936a513 --- /dev/null +++ b/tasks/main.yml @@ -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 diff --git a/templates/haproxy.cfg.jinja b/templates/haproxy.cfg.jinja new file mode 100644 index 0000000..f5db23c --- /dev/null +++ b/templates/haproxy.cfg.jinja @@ -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 %} diff --git a/vars/Debian.yml b/vars/Debian.yml new file mode 100644 index 0000000..24416b5 --- /dev/null +++ b/vars/Debian.yml @@ -0,0 +1,5 @@ +--- + +haproxy_package: haproxy +haproxy_config_path: /etc/haproxy/haproxy.cfg +haproxy_service_name: haproxy diff --git a/vars/FreeBSD.yml b/vars/FreeBSD.yml new file mode 100644 index 0000000..10b7805 --- /dev/null +++ b/vars/FreeBSD.yml @@ -0,0 +1,5 @@ +--- + +haproxy_package: haproxy +haproxy_config_path: /usr/local/etc/haproxy.conf +haproxy_service_name: haproxy diff --git a/vars/RedHat.yml b/vars/RedHat.yml new file mode 100644 index 0000000..24416b5 --- /dev/null +++ b/vars/RedHat.yml @@ -0,0 +1,5 @@ +--- + +haproxy_package: haproxy +haproxy_config_path: /etc/haproxy/haproxy.cfg +haproxy_service_name: haproxy