Skip to content

Commit 536e5d3

Browse files
authored
feat: Install and configure NGINX Plus HA keepalived package (#764)
* And add validation support for NGINX modules while at it
1 parent fed182f commit 536e5d3

File tree

9 files changed

+123
-2
lines changed

9 files changed

+123
-2
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ BREAKING CHANGES:
1010

1111
FEATURES:
1212

13+
- Add support for installing and configuring the NGINX Plus HA keepalived package.
14+
- Add validation tasks to check the Ansible version, the Jinja2 version, whether the required Ansible collections for this role are installed, and whether you are trying to install a valid NGINX module.
1315
- Add support for installing NGINX Open Source on Alpine Linux 3.20.
1416
- Add support for installing NGINX Agent on Ubuntu noble.
15-
- Add validation tasks to check the Ansible version, the Jinja2 version, and whether the required Ansible collections for this role are installed.
1617
- Bump the minimum version of Ansible supported to `2.16`, whilst clarifying that Ansible `2.18` is not supported at this stage.
1718
- Bump the Ansible `community.general` collection to `9.2.0`, `community.crypto` collection to `2.21.1` and `community.docker` collection to `3.11.0`.
1819

@@ -28,6 +29,7 @@ TESTS:
2829
MAINTENANCE:
2930

3031
- Installing certain NGINX modules on Alpine Linux 3.17 no longer requires installing `nginx-plus-module-ndk` as a separate step.
32+
- Add an `ansible_managed` comment to the various templated configs deployed by the role.
3133

3234
CI/CD:
3335

defaults/main/keepalived.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
# Install NGINX Plus HA keepalived package
3+
nginx_keepalived_enable: false
4+
5+
# Configure NGINX Plus HA keepalived
6+
nginx_keepalived_conf_enable: false
7+
nginx_keepalived_conf:
8+
- virtual_router_id: 1
9+
primary_dev: eth0
10+
priority: 101
11+
primary_ip: 192.168.100.100
12+
secondary_ip:
13+
- 192.168.100.101
14+
cluster_ip:
15+
- 192.168.100.150

handlers/main.yml

+6
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@
6666
- logrotate_check['stderr_lines'] != []
6767
- logrotate_check['rc'] != 0
6868
listen: (Handler) Run logrotate
69+
70+
- name: (Handler) Start NGINX Plus HA keepalived
71+
ansible.builtin.service:
72+
name: keepalived
73+
state: restarted
74+
enabled: true

molecule/plus/converge.yml

+11
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@
2929
- set-misc
3030
- subs-filter
3131
- xslt
32+
nginx_keepalived_enable: true
33+
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/main.yml

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@
7474
- nginx_state != 'absent'
7575
tags: nginx_logrotate_config
7676

77+
- name: Install and configure NGINX Plus keepalived HA
78+
ansible.builtin.include_tasks: "{{ role_path }}/tasks/modules/install-packages.yml"
79+
when:
80+
- nginx_keepalived_enable | bool or nginx_keepalived_conf_enable | bool
81+
- nginx_type == 'plus'
82+
- nginx_state != 'absent'
83+
tags: nginx_keepalived
84+
7785
- name: Install NGINX Amplify
7886
ansible.builtin.include_tasks: "{{ role_path }}/tasks/amplify/install-amplify.yml"
7987
when: nginx_amplify_enable | bool

tasks/modules/install-packages.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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'
9+
- ansible_facts['distribution'] != 'Amazon'
10+
notify: (Handler) Start NGINX Plus HA keepalived
11+
12+
- name: Configure NGINX Plus keepalived HA
13+
ansible.builtin.template:
14+
src: keepalived/keepalived.conf.tmpl.j2
15+
dest: /etc/keepalived/keepalived.conf
16+
mode: "0644"
17+
when:
18+
- nginx_keepalived_conf_enable | bool
19+
- ansible_facts['os_family'] != 'Alpine'
20+
- ansible_facts['distribution'] != 'Amazon'
21+
notify: (Handler) Start NGINX Plus HA keepalived

tasks/validate/validate.yml

+13
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,16 @@
9999
- nginx_enable | bool
100100
- (nginx_install_from == "nginx_repository" or nginx_type == "plus")
101101
ignore_errors: true # noqa ignore-errors
102+
103+
- name: Verify that you are installing a supported NGINX dynamic module
104+
ansible.builtin.assert:
105+
that: (nginx_modules | difference(nginx_modules_list) == [] if nginx_type == 'opensource') or (nginx_modules | difference(nginx_plus_modules_list) == [] if nginx_type == 'plus')
106+
success_msg: The NGINX module(s) you are installing are supported.
107+
fail_msg: The NGINX module(s) you are installing are not supported. Please check the README for more details.
108+
when:
109+
- nginx_enable | bool
110+
- nginx_modules is defined
111+
- nginx_modules | length > 0
112+
delegate_to: localhost
113+
become: false
114+
ignore_errors: true # noqa ignore-errors
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{{ ansible_managed | comment }}
2+
3+
global_defs {
4+
vrrp_version 3
5+
}
6+
7+
vrrp_script chk_manual_failover {
8+
script "/usr/lib/keepalived/nginx-ha-manual-failover"
9+
interval 10
10+
weight 50
11+
}
12+
13+
vrrp_script chk_nginx_service {
14+
script "/usr/lib/keepalived/nginx-ha-check"
15+
interval 3
16+
weight 50
17+
}
18+
19+
{% for vrrp in nginx_keepalived_conf %}
20+
vrrp_instance VI_{{ vrrp['virtual_router_id'] }} {
21+
interface {{ vrrp['primary_dev'] }}
22+
priority {{ vrrp['priority'] }}
23+
virtual_router_id {{ vrrp['virtual_router_id'] }}
24+
advert_int 1
25+
accept
26+
garp_master_refresh 5
27+
garp_master_refresh_repeat 1
28+
unicast_src_ip {{ vrrp['primary_ip'] }}
29+
unicast_peer {
30+
{% for ip in vrrp['secondary_ip'] %}
31+
{{ ip }}
32+
{% endfor %}
33+
}
34+
virtual_ipaddress {
35+
{% for ip in vrrp['cluster_ip'] %}
36+
{{ ip }}
37+
{% endfor %}
38+
}
39+
track_script {
40+
chk_nginx_service
41+
chk_manual_failover
42+
}
43+
notify "/usr/lib/keepalived/nginx-ha-notify"
44+
}
45+
{% endfor %}

vars/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,4 @@ openssl_version: 3.0.7
153153
nginx_modules_list: [geoip, image-filter, njs, perl, xslt]
154154

155155
# Supported NGINX Plus dynamic modules
156-
nginx_plus_modules_list: [auth-spnego, brotli, encrypted-session, geoip, geoip2, headers-more, image-filter, lua, ndk, njs, opentracing, passenger, perl, prometheus, rtmp, set-misc, subs-filter, xslt]
156+
nginx_plus_modules_list: [auth-spnego, brotli, encrypted-session, geoip, geoip2, ha-keepalived, headers-more, image-filter, lua, ndk, njs, opentracing, passenger, perl, prometheus, rtmp, set-misc, subs-filter, xslt]

0 commit comments

Comments
 (0)