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' ]

Ansible tags

You can use Ansible --tags or --skip-tags parameters to limit what tasks are performed during Ansible run. This can be used after a host was first configured to speed up playbook execution, when you are sure that most of the configuration is already in the desired state.

Available role tags:

role::keepalived

Main role tag, should be used in the playbook to execute all of the role tasks as well as role dependencies.

Other resources

List of other useful resources related to the debops.keepalived Ansible role: