Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ansible): optimize HAProxy service management in playbook #91

Draft
wants to merge 1 commit into
base: feat/v1.29.3-rev.2
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion roles/haproxy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down