---
- name: Install keepalived
  apt:
    name: keepalived

- name: Configure keepalived
  template:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    owner: root
    group: root
    mode: "{{ item.mode }}"
  loop:
    - src: keepalived.conf.j2
      dest: /etc/keepalived/keepalived.conf
      mode: u=rw,g=,o=
    - src: notify.sh.j2
      dest: /etc/keepalived/notify.sh
      mode: u=rwx,g=,o=
  notify:
    - Reload keepalived

- name: Enable and start keepalived
  systemd:
    name: keepalived
    enabled: true
    state: started
...