From 15d0a5f79c68945a4f2bf00d4527ce426b82b63c Mon Sep 17 00:00:00 2001 From: Santiago Merlos Date: Wed, 31 Jul 2024 16:23:17 +0200 Subject: [PATCH] chore: Update haproxy installation and management tasks --- roles/haproxy/tasks/main.yml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/roles/haproxy/tasks/main.yml b/roles/haproxy/tasks/main.yml index 7dab778..c94b64b 100644 --- a/roles/haproxy/tasks/main.yml +++ b/roles/haproxy/tasks/main.yml @@ -46,6 +46,18 @@ state: present when: ansible_facts['distribution'] == "Debian" +- name: Check if haproxy is already installed + stat: + path: /etc/haproxy/haproxy.cfg + register: haproxy_installed + +- name: Check the current state of haproxy service + systemd: + name: haproxy + state: started + register: haproxy_service + failed_when: false + changed_when: false - name: actually installing haproxy package: @@ -65,12 +77,26 @@ command: "haproxy -f /etc/haproxy/haproxy.cfg -c" when: ansible_os_family in ['RedHat', 'Rocky'] -- name: restarting haproxy service +- name: Ensure haproxy is enabled and running if installed + systemd: + name: haproxy + enabled: yes + state: started + when: haproxy_installed.stat.exists and haproxy_service.status != 0 + +- name: Restart haproxy if not previously installed systemd: daemon_reload: yes name: haproxy enabled: yes state: restarted + when: not haproxy_installed.stat.exists + +- name: Reload haproxy if already installed and running + systemd: + name: haproxy + state: reloaded + when: haproxy_installed.stat.exists and haproxy_service.status == 0 - name: Check if port 6443 is open wait_for: