3 changed files with 56 additions and 0 deletions
@ -0,0 +1,7 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost) |
||||
|
|
||||
|
if [ $STATUS_CODE -lt 200 ] || [ $STATUS_CODE -ge 400 ]; then |
||||
|
exit 1 |
||||
|
fi |
@ -0,0 +1,25 @@ |
|||||
|
- name: Install keepalived packages |
||||
|
apt: |
||||
|
name: |
||||
|
- keepalived |
||||
|
state: latest |
||||
|
update_cache: true |
||||
|
|
||||
|
- name: Copy check_nginx script to {{ vrrp_check_nginx_script_path }} |
||||
|
copy: |
||||
|
src: check_nginx.sh |
||||
|
dest: "{{ vrrp_check_nginx_script_path }}" |
||||
|
owner: root |
||||
|
group: root |
||||
|
mode: 0755 |
||||
|
|
||||
|
- name: Copy keepalived config |
||||
|
template: |
||||
|
src: keepalived.conf.j2 |
||||
|
dest: /etc/keepalived/keepalived.conf |
||||
|
|
||||
|
- name: Restart and enable the keepalived service |
||||
|
ansible.builtin.service: |
||||
|
name: keepalived |
||||
|
state: restarted |
||||
|
enabled: yes |
@ -0,0 +1,24 @@ |
|||||
|
vrrp_script chk_nginx { |
||||
|
script "{{ vrrp_check_nginx_script_path }}" |
||||
|
interval 5 |
||||
|
timeout 3 |
||||
|
weight 2 |
||||
|
} |
||||
|
|
||||
|
vrrp_instance VI_1 { |
||||
|
state MASTER |
||||
|
interface {{ vrrp_interface }} |
||||
|
virtual_router_id 51 |
||||
|
priority 100 |
||||
|
advert_int 1 |
||||
|
authentication { |
||||
|
auth_type PASS |
||||
|
auth_pass {{ vrrp_auth_password }} |
||||
|
} |
||||
|
virtual_ipaddress { |
||||
|
{{ vrrp_virtual_ip }} dev {{ vrrp_interface }} |
||||
|
} |
||||
|
track_script { |
||||
|
chk_nginx |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue