keepalived/tasks/main.yml
2024-04-09 16:42:44 +03:00

67 lines
1.6 KiB
YAML

---
- name: Mask Keepalived before install for Debian OS family
ansible.builtin.systemd:
name: keepalived
masked: yes
when: ansible_facts['os_family'] == 'Debian'
changed_when: false
- name: Install keepalived
package:
name: keepalived
state: present
register: keepalived_setup
- name: Template keepalived.conf
when: keepalived_config_override is not defined
block:
- name: Merge config for keepalived
set_fact:
keepalived_config: "{{ keepalived_default_config | combine(keepalived_config, recursive=true) }}"
- 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
when: keepalived_config_override is defined
- 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
- name: Enable and start keepalived service
systemd:
name: keepalived
state: started
enabled: yes
daemon_reload: yes
masked: no
register: keepalived_enable_and_start