101 lines
3.8 KiB
YAML
101 lines
3.8 KiB
YAML
---
|
|
- block:
|
|
- name: Install the keepalived repository
|
|
apt_repository: repo={{ keepalived_repo }} update_cache=yes
|
|
when: ansible_distribution_major_version <= '16'
|
|
|
|
- name: Install the keepalived package
|
|
apt: name={{ keepalived_pkgs }} state={{ keepalived_pkg_state }} cache_valid_time=1800
|
|
|
|
tags: keepalived
|
|
when:
|
|
- keepalived_install | bool
|
|
- ansible_distribution_file_variety == "Debian"
|
|
|
|
- block:
|
|
- name: Install the user that the keepalived scripts will run under
|
|
user: name={{ keepalived_script_username }} home={{ keepalived_script_user_home }} createhome=no shell=/usr/sbin/nologin system=yes
|
|
|
|
- name: Create the keepalive script user directory
|
|
file: dest={{ keepalived_script_user_home }} state=directory owner={{ keepalived_script_username }} group={{ keepalived_script_username }} mode=0750
|
|
|
|
- name: Create the tmpfile entry for the keepalived runtime directory
|
|
template: src=tmpfile_keepalived.conf.j2 dest=/usr/lib/tmpfiles.d/keepalived.conf owner=root group=root mode=0644
|
|
when: ansible_service_mgr == 'systemd'
|
|
|
|
- name: Install the keepalived configuration
|
|
template: src=keepalived.conf.j2 dest=/etc/keepalived/keepalived.conf owner=root group=root mode=0600
|
|
notify: restart keepalived
|
|
|
|
- name: Install the keepalived default check script
|
|
template: src=keepalived_check_service_status.sh.j2 dest=/usr/local/bin/keepalived_check_service_status owner=root group=root mode=0755
|
|
notify: restart keepalived
|
|
|
|
- name: Install the keepalived notify scripts
|
|
template: src=keepalived_notify.sh.j2 dest={{ item.notify }} owner=root group={{ keepalived_script_username }} mode=0754
|
|
with_items: '{{ keepalived_instances }}'
|
|
|
|
- name: Set the kernel net.ipv4.ip_nonlocal_bind sysctl
|
|
sysctl:
|
|
reload: yes
|
|
state: present
|
|
name: net.ipv4.ip_nonlocal_bind
|
|
sysctl_set: yes
|
|
sysctl_file: /etc/sysctl.d/90-keepalived
|
|
value: 1
|
|
when: keepalived_non_local_bind | bool
|
|
|
|
- name: Disable the kernel net.ipv4.ip_nonlocal_bind sysctl if not needed
|
|
sysctl:
|
|
reload: yes
|
|
state: absent
|
|
name: net.ipv4.ip_nonlocal_bind
|
|
sysctl_set: yes
|
|
sysctl_file: /etc/sysctl.d/90-keepalived
|
|
value: 1
|
|
when: not keepalived_non_local_bind | bool
|
|
|
|
- name: Ensure that keepalived is started and enabled
|
|
service: name=keepalived state=started enabled=yes
|
|
when: keepalived_enabled | bool
|
|
|
|
- name: Ensure that keepalived is stopped and disabled
|
|
service: name=keepalived state=stopped enabled=no
|
|
when: not keepalived_enabled | bool
|
|
|
|
tags: [ 'keepalived', 'keepalived_conf' ]
|
|
when: keepalived_install | bool
|
|
|
|
- block:
|
|
- name: Install the keepalived NRPE nagios check
|
|
copy: src=check_keepalived_state dest={{ nagios_plugins_dir }}/check_keepalived_state owner=root group=root mode=0555
|
|
with_items: '{{ keepalived_instances }}'
|
|
|
|
- name: Install the keepalived NRPE command configuration
|
|
template: src=keepalived-nrpe.cfg.j2 dest={{ nrpe_include_dir }}/keepalived-nrpe.cfg owner=root group=root mode=0444
|
|
notify: Reload NRPE server
|
|
|
|
tags: keepalived
|
|
when:
|
|
- keepalived_install | bool
|
|
- keepalived_nagios_check | bool
|
|
|
|
- block:
|
|
- name: Remove the keepalived package if we do not want it
|
|
apt: name={{ keepalived_pkgs }} state=absent
|
|
|
|
- name: Remove the keepalived notify scripts
|
|
file: dest={{ item.notify }} state=absent
|
|
with_items: '{{ keepalived_instances }}'
|
|
|
|
- name: Remove the keepalived NRPE check
|
|
file: dest={{ nagios_plugins_dir }}/check_keepalived_state state=absent
|
|
with_items: '{{ keepalived_instances }}'
|
|
|
|
- name: Remove the keepalived NRPE command configuration
|
|
file: dest={{ nrpe_include_dir }}/keepalived-nrpe.cfg state=absent
|
|
|
|
tags: keepalived
|
|
when: not keepalived_install | bool
|
|
|