Getting started
Example inventory
To install and configure keepalived
on a given host, it should be included in
a specific Ansible inventory group:
[debops_all_hosts]
hostname ansible_host=hostname.example.org
[debops_service_keepalived]
hostname
Of course, installing keepalived on a single host does not provide any benefits, so it's better to create a cluster instead:
[debops_all_hosts]
node1 ansible_host=node1.example.org
node2 ansible_host=node2.example.org
node3 ansible_host=node3.example.org
[debops_service_keepalived]
node1
node2
node3
You can also create multiple separate keepalived clusters in a single Ansible inventory by using separate host groups. Each host group can have its own configuration:
[debops_all_hosts]
node1 ansible_host=node1.example.org
node2 ansible_host=node2.example.org
node3 ansible_host=node3.example.org
node4 ansible_host=node4.example.org
[cluster_group_one]
node1
node2
[cluster_group_two]
node3
node4
[debops_service_keepalived:children]
cluster_group_one
cluster_group_two
Check the Floating IP address using keepalived documentation section to see how the role can be configured to utilize separate inventory groups.
Example playbook
If you are using this role without DebOps, here's an example Ansible playbook
that uses the debops.keepalived
role:
---
- name: Manage Advanced Package Manager
collections: [ 'debops.debops', 'debops.roles01',
'debops.roles02', 'debops.roles03' ]
hosts: [ 'debops_service_keepalived' ]
become: True
environment: '{{ inventory__environment | d({})
| combine(inventory__group_environment | d({}))
| combine(inventory__host_environment | d({})) }}'
roles:
- role: sysctl
tags: [ 'role::sysctl', 'skip::sysctl' ]
sysctl__dependent_parameters:
- '{{ keepalived__sysctl__dependent_parameters }}'
- role: ferm
tags: [ 'role::ferm', 'skip::ferm' ]
ferm__dependent_rules:
- '{{ keepalived__ferm__dependent_rules }}'
- role: keepalived
tags: [ 'role::keepalived', 'skip::keepalived' ]
Other resources
List of other useful resources related to the debops.keepalived
Ansible role:
Manual pages: keepalived(8), keepalived.conf(5)
Lots of configuration examples can be found in the
/usr/share/doc/keepalived/samples/
directory, provided with thekeepalived
APT package.Example of floating IP address configuration with keepalived. Based on CentOS, however the service configuration is the same on different operating systems.
Example of extending keepalived functionality through scripts.