Обновить playbook1_keepalived.yml

This commit is contained in:
2026-04-06 03:49:39 +00:00
parent f8159766d3
commit 31cdd82336

View File

@@ -1,5 +1,5 @@
--- ---
- name: Configure Keepalived for HA Proxy - name: Configure Keepalived for HA Proxy (ALT Linux)
hosts: proxy hosts: proxy
become: true become: true
vars: vars:
@@ -13,25 +13,17 @@
backup_priority: 100 backup_priority: 100
tasks: tasks:
- name: Install keepalived package - name: Install keepalived package (ALT Linux)
ansible.builtin.apt: ansible.builtin.package:
name: keepalived name: keepalived
state: present state: present
update_cache: true tags:
tags: keepalived - keepalived
- name: Create check_haproxy script directory
ansible.builtin.file:
path: /usr/local/bin
state: directory
mode: '0755'
tags: keepalived
- name: Deploy HAProxy health check script - name: Deploy HAProxy health check script
ansible.builtin.copy: ansible.builtin.copy:
content: | content: |
#!/bin/bash #!/bin/bash
# Check if haproxy is running and listening
if pgrep -x "haproxy" > /dev/null; then if pgrep -x "haproxy" > /dev/null; then
if ss -tlnp | grep -q ":80 "; then if ss -tlnp | grep -q ":80 "; then
exit 0 exit 0
@@ -42,10 +34,11 @@
mode: '0755' mode: '0755'
owner: root owner: root
group: root group: root
tags: keepalived tags:
- keepalived
- name: Configure keepalived.conf - name: Configure keepalived.conf
ansible.builtin.template: ansible.builtin.copy:
content: | content: |
global_defs { global_defs {
router_id {{ inventory_hostname }} router_id {{ inventory_hostname }}
@@ -82,19 +75,19 @@
mode: '0644' mode: '0644'
backup: true backup: true
notify: Restart keepalived notify: Restart keepalived
tags: keepalived tags:
- keepalived
- name: Enable and start keepalived service - name: Enable and start keepalived service
ansible.builtin.systemd: ansible.builtin.systemd:
name: keepalived name: keepalived
enabled: true enabled: true
state: started state: started
daemon_reload: true tags:
tags: keepalived - keepalived
handlers: handlers:
- name: Restart keepalived - name: Restart keepalived
ansible.builtin.systemd: ansible.builtin.systemd:
name: keepalived name: keepalived
state: restarted state: restarted
daemon_reload: true