Files
ansiblerazvert/playbook3_haproxy.yml

84 lines
2.3 KiB
YAML
Raw Normal View History

2026-04-06 03:14:37 +00:00
---
2026-04-06 05:05:33 +00:00
- name: Configure Keepalived for HA Proxy (ALT Linux)
2026-04-06 03:14:37 +00:00
hosts: proxy
become: true
vars:
vip_address: "172.16.1.253"
2026-04-06 05:05:33 +00:00
vip_cidr: "23"
vrrp_instance: "VI_1"
vrrp_id: 51
auth_pass: "ansible_secure_pass"
master_priority: 150
backup_priority: 100
2026-04-06 03:14:37 +00:00
tasks:
2026-04-06 05:05:33 +00:00
- name: Install keepalived package (ALT Linux)
2026-04-06 03:50:09 +00:00
ansible.builtin.package:
2026-04-06 05:05:33 +00:00
name: keepalived
2026-04-06 03:14:37 +00:00
state: present
2026-04-06 03:50:09 +00:00
tags:
2026-04-06 05:05:33 +00:00
- keepalived
2026-04-06 03:14:37 +00:00
2026-04-06 05:05:33 +00:00
- name: Detect network interface
2026-04-06 03:14:37 +00:00
ansible.builtin.shell: |
2026-04-06 05:05:33 +00:00
ip -br link show | grep -E 'UP|UNKNOWN' | grep -v 'lo' | awk '{print $1}' | head -1
register: detected_interface
changed_when: false
2026-04-06 03:50:09 +00:00
tags:
2026-04-06 05:05:33 +00:00
- keepalived
2026-04-06 03:14:37 +00:00
2026-04-06 05:05:33 +00:00
- name: Set interface fact
ansible.builtin.set_fact:
network_interface: "{{ detected_interface.stdout | default('eth0') }}"
2026-04-06 04:14:45 +00:00
tags:
2026-04-06 05:05:33 +00:00
- keepalived
2026-04-06 04:14:45 +00:00
2026-04-06 05:05:33 +00:00
- name: Debug - show detected interface
ansible.builtin.debug:
msg: "Using network interface: {{ network_interface }}"
2026-04-06 04:14:45 +00:00
tags:
2026-04-06 05:05:33 +00:00
- keepalived
2026-04-06 04:14:45 +00:00
2026-04-06 05:05:33 +00:00
- name: Configure keepalived.conf (simple config without health check)
2026-04-06 03:50:09 +00:00
ansible.builtin.copy:
2026-04-06 03:14:37 +00:00
content: |
2026-04-06 05:05:33 +00:00
global_defs {
router_id {{ inventory_hostname }}
2026-04-06 04:14:45 +00:00
}
2026-04-06 05:05:33 +00:00
vrrp_instance {{ vrrp_instance }} {
state {% if inventory_hostname == 'ha1-cod' %}MASTER{% else %}BACKUP{% endif %}
interface {{ network_interface }}
virtual_router_id {{ vrrp_id }}
priority {% if inventory_hostname == 'ha1-cod' %}{{ master_priority }}{% else %}{{ backup_priority }}{% endif %}
advert_int 1
authentication {
auth_type PASS
auth_pass {{ auth_pass }}
}
virtual_ipaddress {
{{ vip_address }}/{{ vip_cidr }}
}
2026-04-06 04:14:45 +00:00
}
2026-04-06 05:05:33 +00:00
dest: /etc/keepalived/keepalived.conf
2026-04-06 03:14:37 +00:00
mode: '0644'
backup: true
2026-04-06 05:05:33 +00:00
notify: Restart keepalived
2026-04-06 03:50:09 +00:00
tags:
2026-04-06 05:05:33 +00:00
- keepalived
2026-04-06 03:14:37 +00:00
2026-04-06 05:05:33 +00:00
- name: Enable and start keepalived service
2026-04-06 03:14:37 +00:00
ansible.builtin.systemd:
2026-04-06 05:05:33 +00:00
name: keepalived
2026-04-06 03:14:37 +00:00
enabled: true
state: started
2026-04-06 05:05:33 +00:00
daemon_reload: true
2026-04-06 03:50:09 +00:00
tags:
2026-04-06 05:05:33 +00:00
- keepalived
2026-04-06 03:14:37 +00:00
handlers:
2026-04-06 05:05:33 +00:00
- name: Restart keepalived
2026-04-06 03:14:37 +00:00
ansible.builtin.systemd:
2026-04-06 05:05:33 +00:00
name: keepalived
state: restarted
daemon_reload: true