forked from ISTI-ansible-roles/ansible-roles
Keepalived: restart the service if the floating IPs disappear on Ubuntu 18.04.
This commit is contained in:
parent
1060ef9300
commit
98dc9c2960
|
@ -10,6 +10,12 @@
|
||||||
- name: Install the user that the keepalived scripts will run under
|
- 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
|
user: name={{ keepalived_script_username }} home={{ keepalived_script_user_home }} createhome=no shell=/usr/sbin/nologin system=yes
|
||||||
|
|
||||||
|
tags: keepalived
|
||||||
|
when:
|
||||||
|
- keepalived_install | bool
|
||||||
|
- ansible_distribution_file_variety == "Debian"
|
||||||
|
|
||||||
|
- block:
|
||||||
- name: Create the keepalive script user directory
|
- 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
|
file: dest={{ keepalived_script_user_home }} state=directory owner={{ keepalived_script_username }} group={{ keepalived_script_username }} mode=0750
|
||||||
|
|
||||||
|
@ -33,7 +39,7 @@
|
||||||
sysctl_set: yes
|
sysctl_set: yes
|
||||||
sysctl_file: /etc/sysctl.d/90-keepalived
|
sysctl_file: /etc/sysctl.d/90-keepalived
|
||||||
value: 1
|
value: 1
|
||||||
when: keepalived_non_local_bind
|
when: keepalived_non_local_bind | bool
|
||||||
|
|
||||||
- name: Disable the kernel net.ipv4.ip_nonlocal_bind sysctl if not needed
|
- name: Disable the kernel net.ipv4.ip_nonlocal_bind sysctl if not needed
|
||||||
sysctl:
|
sysctl:
|
||||||
|
@ -43,18 +49,18 @@
|
||||||
sysctl_set: yes
|
sysctl_set: yes
|
||||||
sysctl_file: /etc/sysctl.d/90-keepalived
|
sysctl_file: /etc/sysctl.d/90-keepalived
|
||||||
value: 1
|
value: 1
|
||||||
when: not keepalived_non_local_bind
|
when: not keepalived_non_local_bind | bool
|
||||||
|
|
||||||
- name: Ensure that keepalived is started and enabled
|
- name: Ensure that keepalived is started and enabled
|
||||||
service: name=keepalived state=started enabled=yes
|
service: name=keepalived state=started enabled=yes
|
||||||
when: keepalived_enabled
|
when: keepalived_enabled | bool
|
||||||
|
|
||||||
- name: Ensure that keepalived is stopped and disabled
|
- name: Ensure that keepalived is stopped and disabled
|
||||||
service: name=keepalived state=stopped enabled=no
|
service: name=keepalived state=stopped enabled=no
|
||||||
when: not keepalived_enabled
|
when: not keepalived_enabled | bool
|
||||||
|
|
||||||
tags: keepalived
|
tags: [ 'keepalived', 'keepalived_conf' ]
|
||||||
when: keepalived_install
|
when: keepalived_install | bool
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Install the keepalived NRPE nagios check
|
- name: Install the keepalived NRPE nagios check
|
||||||
|
@ -67,8 +73,8 @@
|
||||||
|
|
||||||
tags: keepalived
|
tags: keepalived
|
||||||
when:
|
when:
|
||||||
- keepalived_install
|
- keepalived_install | bool
|
||||||
- keepalived_nagios_check
|
- keepalived_nagios_check | bool
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Remove the keepalived package if we do not want it
|
- name: Remove the keepalived package if we do not want it
|
||||||
|
@ -86,5 +92,5 @@
|
||||||
file: dest={{ nrpe_include_dir }}/keepalived-nrpe.cfg state=absent
|
file: dest={{ nrpe_include_dir }}/keepalived-nrpe.cfg state=absent
|
||||||
|
|
||||||
tags: keepalived
|
tags: keepalived
|
||||||
when: not keepalived_install
|
when: not keepalived_install | bool
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,11 @@ global_defs {
|
||||||
{% if keepalived_enable_script_security %}
|
{% if keepalived_enable_script_security %}
|
||||||
|
|
||||||
enable_script_security
|
enable_script_security
|
||||||
|
{% if ansible_distribution_file_variety == "Debian" and ansible_distribution_major_version == '18' %}
|
||||||
|
script_user root
|
||||||
|
{% else %}
|
||||||
script_user {{ keepalived_script_username }}
|
script_user {{ keepalived_script_username }}
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +25,13 @@ vrrp_script {{ script.name }} {
|
||||||
vrrp_instance {{ instance.name }} {
|
vrrp_instance {{ instance.name }} {
|
||||||
interface {{ instance.interface }}
|
interface {{ instance.interface }}
|
||||||
{% if instance.state is defined %}
|
{% if instance.state is defined %}
|
||||||
|
{% if instance.nopreempt is defined and instance.nopreempt %}
|
||||||
|
|
||||||
|
state BACKUP
|
||||||
|
{% else %}
|
||||||
state {{ instance.state }}
|
state {{ instance.state }}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
virtual_router_id {{ instance.vrouter_id }}
|
virtual_router_id {{ instance.vrouter_id }}
|
||||||
priority {{ instance.priority }}
|
priority {{ instance.priority }}
|
||||||
|
|
|
@ -1,4 +1,18 @@
|
||||||
!#/bin/bash
|
#!/bin/bash
|
||||||
|
{% if ansible_distribution_file_variety == "Debian" and ansible_distribution_major_version == '18' %}
|
||||||
|
am_i_master=$( grep MASTER /var/lib/keepalived/keepalive.state )
|
||||||
|
keepalive_master=$?
|
||||||
|
|
||||||
|
if [ $keepalive_master -eq 0 ] ; then
|
||||||
|
{% for instance in keepalived_instances %}
|
||||||
|
{% for addr in instance.v_addr %}
|
||||||
|
float_ip=$( ip addr show | grep {{ addr }} )
|
||||||
|
retval=$?
|
||||||
|
[ $retval -eq 1 ] && /bin/systemctl restart keepalived
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
fi
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{{ keepalived_script1_check }}
|
{{ keepalived_script1_check }}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue