2023-02-07 22:42:20 +00:00
|
|
|
---
|
2023-08-30 11:12:31 +00:00
|
|
|
- name: Mask Keepalived before install for Debian OS family
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
name: keepalived
|
|
|
|
masked: yes
|
|
|
|
when: ansible_facts['os_family'] == 'Debian'
|
2024-04-09 13:42:44 +00:00
|
|
|
changed_when: false
|
2023-08-30 11:12:31 +00:00
|
|
|
|
2023-02-07 22:42:20 +00:00
|
|
|
- name: Install keepalived
|
|
|
|
package:
|
|
|
|
name: keepalived
|
|
|
|
state: present
|
|
|
|
register: keepalived_setup
|
|
|
|
|
2024-04-09 13:42:44 +00:00
|
|
|
- name: Template keepalived.conf
|
2024-09-29 01:34:31 +00:00
|
|
|
when: keepalived_config_override is not defined or keepalived_config_override | length <= 0
|
2024-04-09 13:42:44 +00:00
|
|
|
block:
|
2023-02-07 22:42:20 +00:00
|
|
|
- name: Merge config for keepalived
|
|
|
|
set_fact:
|
2024-05-15 12:54:29 +00:00
|
|
|
keepalived_combined_config: "{{ keepalived_default_config | default({}) | combine(keepalived_config| default({}), recursive=true) }}"
|
2023-02-07 22:42:20 +00:00
|
|
|
|
|
|
|
- name: Add keepalived config
|
|
|
|
template:
|
|
|
|
src: "keepalived.conf.j2"
|
|
|
|
dest: "/etc/keepalived/keepalived.conf"
|
|
|
|
notify:
|
|
|
|
- Restart keepalived
|
|
|
|
|
|
|
|
- name: Override keepalived config
|
|
|
|
copy:
|
|
|
|
content: "{{ keepalived_config_override }}"
|
|
|
|
dest: "/etc/keepalived/keepalived.conf"
|
|
|
|
notify:
|
|
|
|
- Restart keepalived
|
2024-05-15 12:54:29 +00:00
|
|
|
when:
|
|
|
|
- keepalived_config_override is defined
|
|
|
|
- keepalived_config_override | length > 0
|
2024-04-09 13:42:44 +00:00
|
|
|
|
|
|
|
- name: Create dir for scripts
|
|
|
|
file:
|
|
|
|
name: /etc/keepalived/scripts
|
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: Create scripts for keepalived
|
|
|
|
copy:
|
|
|
|
content: "{{ item.data }}"
|
|
|
|
dest: "/etc/keepalived/scripts/{{ item.name }}"
|
|
|
|
mode: 0755
|
|
|
|
loop: "{{ keepalived_scripts }}"
|
|
|
|
notify:
|
|
|
|
- Restart keepalived
|
|
|
|
when: keepalived_scripts is defined
|
|
|
|
|
|
|
|
- name: Unmask Keepalived after install for Debian OS family
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
name: keepalived
|
|
|
|
masked: no
|
|
|
|
when: ansible_facts['os_family'] == 'Debian'
|
|
|
|
changed_when: false
|
2023-02-07 22:42:20 +00:00
|
|
|
|
|
|
|
- name: Enable and start keepalived service
|
|
|
|
systemd:
|
|
|
|
name: keepalived
|
|
|
|
state: started
|
|
|
|
enabled: yes
|
|
|
|
daemon_reload: yes
|
2023-08-30 11:12:31 +00:00
|
|
|
masked: no
|
2023-02-07 22:42:20 +00:00
|
|
|
register: keepalived_enable_and_start
|