WIP
This commit is contained in:
16
ansible/roles/vip/defaults/main.yml
Normal file
16
ansible/roles/vip/defaults/main.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
# Required
|
||||
vip_script_user: null
|
||||
vip_monitored_process: null
|
||||
vip_vrrp_password: null # Max 8 characters
|
||||
vip_vrrp_ips: null
|
||||
# - master: <string>
|
||||
# virtual_router_id: <int>
|
||||
# addr: <string>
|
||||
|
||||
# Optionnal
|
||||
vip_alerts_to: null
|
||||
# - <string>
|
||||
|
||||
# Required if length vip_alerts_to > 0
|
||||
vip_smtp_from: null
|
||||
vip_smtp_relay: null
|
||||
4
ansible/roles/vip/handlers/main.yml
Normal file
4
ansible/roles/vip/handlers/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
- name: Restart keepalived
|
||||
ansible.builtin.service:
|
||||
name: "keepalived"
|
||||
state: "restarted"
|
||||
28
ansible/roles/vip/tasks/main.yml
Normal file
28
ansible/roles/vip/tasks/main.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
- name: Installation des paquetages
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- "keepalived"
|
||||
notify:
|
||||
- "Restart keepalived"
|
||||
|
||||
- name: Tell kernel to allow binding non-local IP
|
||||
ansible.posix.sysctl:
|
||||
name: "net.ipv4.ip_nonlocal_bind"
|
||||
value: "1"
|
||||
sysctl_set: true
|
||||
notify:
|
||||
- "Restart keepalived"
|
||||
|
||||
- name: Generate keepalived.conf file
|
||||
ansible.builtin.template:
|
||||
src: "templates/keepalived.conf"
|
||||
dest: "/etc/keepalived/keepalived.conf"
|
||||
mode: "0640"
|
||||
notify:
|
||||
- "Restart keepalived"
|
||||
|
||||
- name: Activate and start keepalived
|
||||
ansible.builtin.service:
|
||||
name: "keepalived"
|
||||
state: "started"
|
||||
enabled: true
|
||||
45
ansible/roles/vip/templates/keepalived.conf
Normal file
45
ansible/roles/vip/templates/keepalived.conf
Normal file
@@ -0,0 +1,45 @@
|
||||
global_defs {
|
||||
enable_script_security
|
||||
script_user "{{ vip_script_user }}"
|
||||
{% if vip_alerts_to | default([]) | length > 0 %}
|
||||
|
||||
notification_email {
|
||||
{% for dest in vip_alerts_to %}
|
||||
{{ dest }}
|
||||
{% endfor %}
|
||||
}
|
||||
notification_email_from {{ vip_smtp_from }}
|
||||
smtp_server {{ vip_smtp_relay }}
|
||||
smtp_connect_timeout 30
|
||||
router_id {{ ansible_hostname }}
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
vrrp_script chk_{{ vip_monitored_process }} {
|
||||
script "/usr/bin/killall -0 {{ vip_monitored_process }}" # Check if process is running
|
||||
interval 2 # Check every 2 seconds
|
||||
weight 2 # Weight to influence master election
|
||||
}
|
||||
{% for ip in vip_vrrp_ips %}
|
||||
|
||||
# master: {{ ip.master }}
|
||||
vrrp_instance VI_{{ ip.virtual_router_id }} {
|
||||
state {{ (ansible_hostname==ip.master) | ternary('MASTER', 'BACKUP') }}
|
||||
interface eth0
|
||||
virtual_router_id {{ ip.virtual_router_id }}
|
||||
priority {{ (ansible_hostname==ip.master) | ternary('101', '100') }}
|
||||
advert_int 1
|
||||
promote_secondaries
|
||||
smtp_alert true
|
||||
authentication {
|
||||
auth_type PASS
|
||||
auth_pass {{ vip_vrrp_password }}
|
||||
}
|
||||
virtual_ipaddress {
|
||||
{{ ip.addr }}
|
||||
}
|
||||
track_script {
|
||||
chk_{{ vip_monitored_process }}
|
||||
}
|
||||
}
|
||||
{% endfor %}
|
||||
Reference in New Issue
Block a user