- name: Get IP range.
  shell: "echo {{ network_allowed }} | cut -d'.' --fields=1,2,3"
  register: result

- name: Get interface name.
  shell: "ip -4 addr show | grep {{ result.stdout }} | rev | cut -d ' ' -f 1 | rev"
  register: itfn

- name: Set keepalived_bind_interface.
  set_fact:
    keepalived_bind_interface: "{{ itfn.stdout }}"

- name: Integration net.ipv4
  blockinfile:
    dest: /etc/sysctl.conf
    block: |
      net.ipv4.ip_forward = 1
      net.ipv4.ip_nonlocal_bind = 1

- name: Ensure keepalived is started and enabled on boot.
  service: name=keepalived state=started enabled=yes

- name: Ensure keepalived conf is set 
  template: >
    src=templates/keepalived.conf.j2
    dest=/etc/keepalived/keepalived.conf

