Add first version of Keepalived role
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Tristan PILAT 2021-02-11 17:32:01 +01:00
parent 17f1a1a55e
commit 58f82046cc
5 changed files with 74 additions and 0 deletions

16
keepalived/README.md Normal file
View file

@ -0,0 +1,16 @@
# keepalived
Install Keepalived
## Tasks
Everything is in the `tasks/main.yml` file.
## Available variables
* `keepalived_interface` : Interface used by vrrpd instance (default is the interface reported by ansible_default_ipv4.interface)
* `keepalived_role` : This can be either master or backup (default: `master`)
* `keepalived_router_id` : Number between 0 and 255 used to differentiate multiple instances of vrrpd (default: `42`)
* `keepalived_priority` : Used for electing MASTER, highest priority wins (default : `100` when keepalived_role is set to `master` otherwise `50`)
* `keepalived_ip` : Address added or deleted on change to MASTER/BACKUP. This is mandatory (default: none)
* `keepalived_password` : Password for accessing vrrpd. Should be the same on all machines. This is mandatory (default: none)

View file

@ -0,0 +1,6 @@
keepalived_interface: "{{ ansible_default_ipv4.interface }}"
keepalived_role: "master"
keepalived_router_id: "42"
keepalived_priority: "{% if keepalived_role == 'master' %}100{% else %}50{% endif %}"
keepalived_ip: ""
keepalived_password: ""

View file

@ -0,0 +1,5 @@
---
- name: restart keepalived
systemd:
name: keepalived
state: restarted

18
keepalived/tasks/main.yml Normal file
View file

@ -0,0 +1,18 @@
- name: install Keepalived service
apt:
pkg: keepalived
state: present
- name: generate Keepalived configuration
template:
src: keepalived.conf.j2
dest: /etc/keepalived/keepalived.conf
mode: 0644
notify: restart keepalived
- name: enable and restart Keepalived service
systemd:
name: keepalived
daemon_reload: yes
state: started
enabled: yes

View file

@ -0,0 +1,29 @@
# {{ ansible_managed }}
vrrp_script chk_sshd {
script "/usr/bin/pkill -0 sshd"
interval 5
weight -4
fall 2
rise 1
}
vrrp_instance vrrp {
interface {{ keepalived_interface | mandatory }}
virtual_router_id {{ keepalived_router_id | mandatory }}
state {{ keepalived_role | upper }}
priority {{ keepalived_priority }}
virtual_ipaddress {
{{ keepalived_ip | mandatory }}
}
authentication {
auth_type PASS
auth_pass {{ keepalived_password | mandatory }}
}
track_script {
chk_sshd
}
}