You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
- name: Setup HAProxy
|
|
|
|
hosts: all
|
|
|
|
become: yes
|
|
|
|
become_method: sudo
|
|
|
|
become_user: root
|
|
|
|
tasks:
|
|
|
|
- name: Install package
|
|
|
|
package:
|
|
|
|
name: haproxy
|
|
|
|
state: present
|
|
|
|
- name: Start HAProxy
|
|
|
|
service:
|
|
|
|
name: haproxy
|
|
|
|
enabled: true
|
|
|
|
state: started
|
|
|
|
- name: Install keepalived
|
|
|
|
package:
|
|
|
|
name: keepalived
|
|
|
|
state: present
|
|
|
|
- name: Start keepalived
|
|
|
|
service:
|
|
|
|
name: keepalived
|
|
|
|
enabled: true
|
|
|
|
state: started
|
|
|
|
- name: Create keepalived empty config
|
|
|
|
copy:
|
|
|
|
dest: /etc/keepalived/keepalived.conf
|
|
|
|
content: ""
|
|
|
|
- name: Config keepalived
|
|
|
|
blockinfile:
|
|
|
|
dest: /etc/keepalived/keepalived.conf
|
|
|
|
block: |
|
|
|
|
vrrp_script chk_apiserver {
|
|
|
|
script "/usr/bin/nc localhost 6443"
|
|
|
|
interval 5
|
|
|
|
}
|
|
|
|
vrrp_instance VI_1 {
|
|
|
|
state MASTER
|
|
|
|
interface eth0
|
|
|
|
virtual_router_id 101
|
|
|
|
priority 100
|
|
|
|
advert_int 1
|
|
|
|
authentication {
|
|
|
|
auth_type PASS
|
|
|
|
auth_pass 1111
|
|
|
|
}
|
|
|
|
virtual_ipaddress {
|
|
|
|
10.10.0.2
|
|
|
|
}
|
|
|
|
track_script {
|
|
|
|
chk_apiserver
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vrrp_script chk_haproxy {
|
|
|
|
script "/usr/bin/pidof haproxy"
|
|
|
|
interval 2
|
|
|
|
}
|
|
|
|
vrrp_instance VI_2 {
|
|
|
|
state MASTER
|
|
|
|
interface eth0
|
|
|
|
virtual_router_id 102
|
|
|
|
priority 100
|
|
|
|
advert_int 1
|
|
|
|
authentication {
|
|
|
|
auth_type PASS
|
|
|
|
auth_pass 2222
|
|
|
|
}
|
|
|
|
virtual_ipaddress {
|
|
|
|
10.10.0.3
|
|
|
|
}
|
|
|
|
track_script {
|
|
|
|
chk_haproxy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
- name: restart keepalived
|
|
|
|
service:
|
|
|
|
name: keepalived
|
|
|
|
state: restarted
|
|
|
|
|