Skip to content

Commit 7edb02b

Browse files
committed
improve template and fix target install platforms
1 parent baf20e1 commit 7edb02b

File tree

5 files changed

+38
-19
lines changed

5 files changed

+38
-19
lines changed

defaults/main/keepalived.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
---
2+
nginx_keepalived_enable: false
23
nginx_keepalived_conf_enable: false
34
nginx_keepalived_conf:
45
- virtual_router_id: 1
56
primary_dev: eth0
67
priority: 101
78
primary_ip: 192.168.100.100
8-
secondary_ip: 192.168.100.101
9-
cluster_ip: 192.168.100.150
9+
secondary_ip:
10+
- 192.168.100.101
11+
cluster_ip:
12+
- 192.168.100.150

molecule/plus/converge.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,14 @@
2929
- set-misc
3030
- subs-filter
3131
- xslt
32+
nginx_keepalived_enable: true
3233
nginx_keepalived_conf_enable: true
34+
nginx_keepalived_conf:
35+
- virtual_router_id: 1
36+
primary_dev: eth0
37+
priority: 101
38+
primary_ip: 192.168.100.100
39+
secondary_ip:
40+
- 192.168.100.101
41+
cluster_ip:
42+
- 192.168.100.150

tasks/modules/install-keepalived.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

tasks/modules/install-packages.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
- name: Install NGINX Plus HA keepalived package
3+
ansible.builtin.package:
4+
name: nginx-ha-keepalived
5+
state: present
6+
when:
7+
- nginx_keepalived_enable | bool
8+
- ansible_facts['os_family'] != 'Alpine' or ansible_facts['distribution'] != 'Amazon'
9+
notify: (Handler) Start NGINX Plus HA keepalived
10+
11+
- name: Configure NGINX Plus keepalived HA
12+
ansible.builtin.template:
13+
src: keepalived/keepalived.conf.tmpl.j2
14+
dest: /etc/keepalived/keepalived.conf
15+
mode: "0644"
16+
when:
17+
- nginx_keepalived_conf_enable | bool
18+
- ansible_facts['os_family'] != 'Alpine' or ansible_facts['distribution'] != 'Amazon'
19+
notify: (Handler) Start NGINX Plus HA keepalived

templates/keepalived/keepalived.conf.tmpl.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ vrrp_instance VI_{{ vrrp['virtual_router_id'] }} {
2727
garp_master_refresh_repeat 1
2828
unicast_src_ip {{ vrrp['primary_ip'] }}
2929
unicast_peer {
30+
{% for ip in vrrp['secondary_ip'] %}
3031
{{ vrrp['secondary_ip'] }}
32+
{% endfor %}
3133
}
3234
virtual_ipaddress {
35+
{% for ip in {{ vrrp['cluster_ip'] }} %}
3336
{{ vrrp['cluster_ip'] }}
37+
{% endfor %}
3438
}
3539
track_script {
3640
chk_nginx_service

0 commit comments

Comments
 (0)