--- - name: Configure Keepalived for HA Proxy (ALT Linux) hosts: proxy become: true vars: vip_address: "172.16.1.253" vip_cidr: "23" vrrp_instance: "VI_1" vrrp_id: 51 auth_pass: "ansible_secure_pass" master_priority: 150 backup_priority: 100 tasks: - name: Install keepalived package (ALT Linux) ansible.builtin.package: name: keepalived state: present tags: - keepalived - name: Detect network interface ansible.builtin.shell: | ip -br link show | grep -E 'UP|UNKNOWN' | grep -v 'lo' | awk '{print $1}' | head -1 register: detected_interface changed_when: false tags: - keepalived - name: Set interface fact ansible.builtin.set_fact: network_interface: "{{ detected_interface.stdout | default('eth0') }}" tags: - keepalived - name: Debug - show detected interface ansible.builtin.debug: msg: "Using network interface: {{ network_interface }}" tags: - keepalived - name: Configure keepalived.conf (simple config without health check) ansible.builtin.copy: content: | global_defs { router_id {{ inventory_hostname }} } 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 }} } } dest: /etc/keepalived/keepalived.conf mode: '0644' backup: true notify: Restart keepalived tags: - keepalived - name: Enable and start keepalived service ansible.builtin.systemd: name: keepalived enabled: true state: started daemon_reload: true tags: - keepalived handlers: - name: Restart keepalived ansible.builtin.systemd: name: keepalived state: restarted daemon_reload: true