diff --git a/roles/keepalived/handlers/main.yml b/roles/keepalived/handlers/main.yml new file mode 100644 index 0000000..df390cb --- /dev/null +++ b/roles/keepalived/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: Reload keepalived + systemd: + name: keepalived.service + state: reloaded +... diff --git a/roles/keepalived/tasks/main.yml b/roles/keepalived/tasks/main.yml new file mode 100644 index 0000000..6889024 --- /dev/null +++ b/roles/keepalived/tasks/main.yml @@ -0,0 +1,21 @@ +--- +- name: Install keepalived + apt: + name: keepalived + +- name: Configure keepalived + template: + src: keepalived.conf + dest: /etc/keepalived/keepalived.conf + owner: root + group: root + mode: u=rw,g=,o= + notify: + - Reload keepalived + +- name: Enable and start keepalived + systemd: + name: keepalived + enabled: true + state: started +... diff --git a/roles/keepalived/templates/keepalived.conf b/roles/keepalived/templates/keepalived.conf new file mode 100644 index 0000000..e5d3331 --- /dev/null +++ b/roles/keepalived/templates/keepalived.conf @@ -0,0 +1,58 @@ +{{ ansible_managed | comment }} + +global_defs { + dynamic_interfaces + script_user root + enable_script_security + vrrp_version 3 +} + +vrrp_sync_group group { + group { + instance_v4 + instance_v6 + } +{% if keepalived_notify_master %} + notify_master "{{ keepalived_notify_master }}" +{% endif %} +{% if keepalived_notify_backup is defined %} + notify_backup "{{ keepalived_notify_backup }}" +{% endif %} +{% if keepalived_notify_fault is defined %} + notify_fault "{{ keepalived_notify_fault }}" +{% endif %} +} + +vrrp_instance instance_v4 { + virtual_router_id {{ keepalived_virtual_router_id }} + interface {{ keepalived_interface }} + state BACKUP + priority 250 + nopreempt + advert_int 1 + accept + virtual_ipaddress { +{% for dev, addrs in keepalived_virtual_addresses_v4.items() %} +{% for addr in addrs %} + {{ addr }} dev {{ dev }} +{% endfor %} +{% endfor %} + } +} + +vrrp_instance instance_v6 { + virtual_router_id {{ keepalived_virtual_router_id }} + interface {{ keepalived_interface }} + state BACKUP + priority 250 + nopreempt + advert_int 1 + accept + virtual_ipaddress { +{% for dev, addrs in keepalived_virtual_addresses_v6.items() %} +{% for addr in addrs %} + {{ addr }} dev {{ dev }} +{% endfor %} +{% endfor %} + } +}