--- - name: Install needed packages package: name: "{{ item }}" state: present update_cache: yes with_items: - keepalived - curl notify: Restart keepalived - name: Install check_apiserver.sh script for keepalived template: src: etc/keepalived/check_apiserver.sh.j2 dest: /etc/keepalived/check_apiserver.sh - name: Install keepalived config file template: src: etc/keepalived/keepalived.conf.j2 dest: /etc/keepalived/keepalived.conf with_items: - { lbip: '{{ lbip_kubeapiserver }}', state: "MASTER", interface: '{{ lb_interface }}', auth_pass: '{{ lb_auth_pass }}' } when: - groups['KubernetesMasters'][0] == ansible_hostname notify: Restart keepalived - name: Install keepalived config file template: src: etc/keepalived/keepalived.conf.j2 dest: /etc/keepalived/keepalived.conf with_items: - { lbip: '{{ lbip_kubeapiserver }}', state: "BACKUP", interface: '{{ lb_interface }}', auth_pass: '{{ lb_auth_pass }}' } when: - not groups['KubernetesMasters'][0] == ansible_hostname notify: Restart keepalived