Skip to content

Commit cfc23e8

Browse files
committed
feat: Add NGINX Agent config template
1 parent fed182f commit cfc23e8

File tree

6 files changed

+227
-26
lines changed

6 files changed

+227
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ BREAKING CHANGES:
1010

1111
FEATURES:
1212

13+
- Add support for templating the entire NGINX Agent configuration file.
1314
- Add support for installing NGINX Open Source on Alpine Linux 3.20.
1415
- Add support for installing NGINX Agent on Ubuntu noble.
1516
- Add validation tasks to check the Ansible version, the Jinja2 version, and whether the required Ansible collections for this role are installed.

defaults/main/agent.yml

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,86 @@
11
---
2-
# Install NGINX Agent.
2+
# Install the NGINX Agent.
33
# Requires access to either the NGINX stub_status or the NGINX Plus REST API.
44
nginx_agent_enable: false
55

6-
# Specify the NGINX Agent data plane key/token.
7-
# This is required to authenticate the NGINX Agent with the NGINX One SaaS control plane available in F5 Distributed Cloud.
8-
# Default is null.
9-
nginx_agent_data_plane_key: null
6+
# Configure the NGINX Agent.
7+
nginx_agent_configure: false
108

11-
# Specify the control plane server host and port.
9+
#######################################################################################################################
10+
# The following parameters let you configure NGINX Agent. #
11+
# By default, the config produced is as close a match to the default config provided by NGINX Agent upon installation.#
12+
#######################################################################################################################
13+
14+
# Specify the NGINX Agent API host and port. Optionally, specify the path to the cert and key.
15+
# Default is not enabled.
16+
# nginx_agent_api:
17+
# host: 127.0.0.1
18+
# port: 8081
19+
# cert: /path/to/cert
20+
# key: /path/to/key
21+
22+
# Specify the control plane server host, port, and data plane key/token.
23+
# The data plane key is required to authenticate NGINX Agent with the NGINX One SaaS control plane available in F5 Distributed Cloud.
1224
# Default is the NGINX One SaaS control plane available in F5 Distributed Cloud.
13-
nginx_agent_server_host: agent.connect.nginx.com
14-
nginx_agent_server_port: 443
25+
# nginx_agent_server:
26+
# host: agent.connect.nginx.com
27+
# port: 443
28+
# data_plane_key: ''
29+
30+
# Enable TLS communication between data plane and control plane.
31+
# Optionally, specify the path to the TLS certificate, key, and CA certificate to enable mTLS.
32+
# nginx_agent_tls:
33+
# enable: true
34+
# skip_verify: false
35+
# cert: /path/to/cert
36+
# key: /path/to/key
37+
# ca: /path/to/ca
38+
39+
# Specify the log level and path.
40+
# Default is info for the log level and /var/log/nginx-agent/ for the log path.
41+
nginx_agent_log:
42+
level: info
43+
path: /var/log/nginx-agent/
44+
45+
# Specify NGINX specific options within NGINX Agent.
46+
# Default is to not exclude any logs, to use the default socket path and to not treat warnings as errors.
47+
nginx_agent_nginx:
48+
exclude_logs: '""'
49+
socket: '"unix:/var/run/nginx-agent/nginx.sock"'
50+
# treat_warnings_as_errors: false
51+
52+
# Specify how often NGINX Agent polls the dataplane.
53+
# Default is 30s for poll interval and 24h for report interval.
54+
nginx_agent_dataplane_status:
55+
poll_interval: 30s
56+
report_interval: 24h
57+
58+
# Specify how often NGINX Agent reports metrics to the control plane.
59+
# Default is 20 for the buffer/bulk size, 1m for report interval, 15s for collection interval and aggregated for mode.
60+
nginx_agent_metrics:
61+
bulk_size: 20
62+
report_interval: 1m
63+
collection_interval: 15s
64+
mode: aggregated
65+
66+
# NGINX Open Source default config paths.
67+
# Default can be seen below.
68+
# nginx_agent_config_dirs: '"/etc/nginx:/usr/local/etc/nginx:/usr/share/nginx/modules"'
69+
70+
# Internal NGINX Agent queue size.
71+
# Default is 100.
72+
# nginx_agent_queue_size: 100
73+
74+
# NGINX Agent features.
75+
# Default is an empty list. See https://docs.nginx.com/nginx-agent/configuration/configuration-overview/ for more details.
76+
# nginx_agent_features: []
77+
78+
# NGINX Agent extensions.
79+
# Default is an empty list. To enable NGINX App Protect reporting within NGINX Agent, use the 'nginx-app-protect' extension as below.
80+
# nginx_agent_extensions: ['nginx-app-protect']
1581

16-
# Enable TLS communication between data plane and control plane
17-
# Default is true.
18-
nginx_agent_tls_enable: true
19-
nginx_agent_tls_skip_verify: false
82+
# NGINX Agent NGINX App Protect settings.
83+
# Default is not enabled.
84+
# nginx_agent_app_protect:
85+
# report_interval: 15s
86+
# precompiled_publication: true

handlers/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
- name: (Handler) Start NGINX Agent
4747
ansible.builtin.service:
4848
name: nginx-agent
49-
state: started
49+
state: restarted
5050
enabled: true
5151

5252
- name: (Handler) Start logrotate

molecule/agent/converge.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,21 @@
77
name: ansible-role-nginx
88
vars:
99
nginx_agent_enable: true
10-
nginx_agent_data_plane_key: "{{ lookup('env', 'AGENT_DATA_PLANE_KEY') }}"
10+
nginx_agent_configure: true
11+
nginx_agent_server:
12+
host: agent.connect.nginx.com
13+
port: 443
14+
data_plane_key: "{{ lookup('env', 'AGENT_DATA_PLANE_KEY') }}"
15+
nginx_agent_tls:
16+
enable: true
17+
skip_verify: false
18+
nginx_agent_nginx:
19+
exclude_logs: '""'
20+
socket: '"unix:/var/run/nginx-agent/nginx.sock"'
21+
treat_warnings_as_errors: false
22+
nginx_agent_config_dirs: '"/etc/nginx:/usr/local/etc/nginx:/usr/share/nginx/modules"'
23+
nginx_agent_queue_size: 100
24+
nginx_agent_extensions: ['metrics']
25+
nginx_agent_api:
26+
host: 127.0.0.1
27+
port: 8081

tasks/agent/install-agent.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,10 @@
99
state: present
1010

1111
- name: Configure NGINX Agent
12-
ansible.builtin.blockinfile:
13-
backup: true
12+
ansible.builtin.template:
13+
src: nginx-agent/nginx-agent.conf.j2
14+
dest: /etc/nginx-agent/nginx-agent.conf
1415
mode: "0644"
15-
path: /etc/nginx-agent/nginx-agent.conf
16-
block: |
17-
server:
18-
{{ ("token: " + nginx_agent_data_plane_key) if nginx_agent_data_plane_key is defined and nginx_agent_data_plane_key | length > 0 }}
19-
host: {{ nginx_agent_server_host }}
20-
grpcPort: {{ nginx_agent_server_port }}
21-
22-
tls:
23-
enable: {{ nginx_agent_tls_enable }}
24-
skip_verify: {{ nginx_agent_tls_skip_verify }}
16+
backup: true
17+
when: nginx_agent_configure | bool
2518
notify: (Handler) Start NGINX Agent
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{{ ansible_managed | comment }}
2+
3+
{% if nginx_agent_server is defined and nginx_agent_server is mapping %}
4+
server:
5+
{% if nginx_agent_server['data_plane_key'] is defined %}
6+
token: {{ nginx_agent_server['data_plane_key'] }}
7+
{% endif %}
8+
host: {{ nginx_agent_server['host'] }}
9+
grpcPort: {{ nginx_agent_server['port'] }}
10+
{% endif %}
11+
12+
{% if nginx_agent_tls is defined and nginx_agent_tls is mapping %}
13+
tls:
14+
enable: {{ nginx_agent_tls['enable'] | bool }}
15+
skip_verify: {{ nginx_agent_tls['skip_verify'] | bool }}
16+
{% if nginx_agent_tls['cert'] is defined %}
17+
cert: {{ nginx_agent_tls['cert'] }}
18+
{% endif %}
19+
{% if nginx_agent_tls['key'] is defined %}
20+
key: {{ nginx_agent_tls['key'] }}
21+
{% endif %}
22+
{% if nginx_agent_tls['ca'] is defined %}
23+
ca: {{ nginx_agent_tls['ca'] }}
24+
{% endif %}
25+
{% endif %}
26+
27+
{% if nginx_agent_log is defined and nginx_agent_log is mapping %}
28+
log:
29+
{% if nginx_agent_log['level'] is defined %}
30+
level: {{ nginx_agent_log['level'] }}
31+
{% endif %}
32+
{% if nginx_agent_log['path'] is defined %}
33+
path: {{ nginx_agent_log['path'] }}
34+
{% endif %}
35+
{% endif %}
36+
37+
{% if nginx_agent_nginx is defined and nginx_agent_nginx is mapping %}
38+
nginx:
39+
{% if nginx_agent_nginx['exclude_logs'] is defined %}
40+
exclude_logs: {{ nginx_agent_nginx['exclude_logs'] }}
41+
{% endif %}
42+
{% if nginx_agent_nginx['socket'] is defined %}
43+
socket: {{ nginx_agent_nginx['socket'] }}
44+
{% endif %}
45+
{% if nginx_agent_nginx['treat_warnings_as_errors'] is defined and nginx_agent_nginx['treat_warnings_as_errors'] is boolean %}
46+
treat_warnings_as_errors: {{ nginx_agent_nginx['treat_warnings_as_errors'] | ternary('true', 'false') }}
47+
{% endif %}
48+
{% endif %}
49+
50+
{% if nginx_agent_dataplane_status is defined and nginx_agent_dataplane_status is mapping %}
51+
dataplane:
52+
status:
53+
{% if nginx_agent_dataplane_status['poll_interval'] is defined %}
54+
poll_interval: {{ nginx_agent_dataplane_status['poll_interval'] }}
55+
{% endif %}
56+
{% if nginx_agent_dataplane_status['report_interval'] is defined %}
57+
report_interval: {{ nginx_agent_dataplane_status['report_interval'] }}
58+
{% endif %}
59+
{% endif %}
60+
61+
{% if nginx_agent_metrics is defined and nginx_agent_metrics is mapping %}
62+
metrics:
63+
{% if nginx_agent_metrics['bulk_size'] is defined and nginx_agent_metrics['bulk_size'] is number %}
64+
bulk_size: {{ nginx_agent_metrics['bulk_size'] }}
65+
{% endif %}
66+
{% if nginx_agent_metrics['report_interval'] is defined %}
67+
report_interval: {{ nginx_agent_metrics['report_interval'] }}
68+
{% endif %}
69+
{% if nginx_agent_metrics['collection_interval'] is defined %}
70+
collection_interval: {{ nginx_agent_metrics['collection_interval'] }}
71+
{% endif %}
72+
{% if nginx_agent_metrics['mode'] is defined %}
73+
mode: {{ nginx_agent_metrics['mode'] }}
74+
{% endif %}
75+
{% endif %}
76+
77+
{% if nginx_agent_config_dirs is defined %}
78+
config_dirs: {{ nginx_agent_config_dirs }}
79+
{% endif %}
80+
81+
{% if nginx_agent_queue_size is defined and nginx_agent_queue_size is number %}
82+
queue_size: {{ nginx_agent_queue_size }}
83+
{% endif %}
84+
85+
{% if nginx_agent_features is defined and nginx_agent_features is not mapping and nginx_agent_features is not string and nginx_agent_features | length > 0 %}
86+
features:
87+
{% for feature in nginx_agent_features %}
88+
{{ "- " + feature }}
89+
{% endfor %}
90+
{% endif %}
91+
92+
{% if nginx_agent_extensions is defined and nginx_agent_extensions is not mapping and nginx_agent_extensions is not string and nginx_agent_extensions | length > 0 %}
93+
extensions:
94+
{% for extension in nginx_agent_extensions %}
95+
{{ "- " + extension }}
96+
{% endfor %}
97+
{% endif %}
98+
99+
{% if nginx_agent_app_protect is defined and nginx_agent_app_protect is mapping %}
100+
nginx_app_protect:
101+
{% if nginx_agent_app_protect['report_interval'] is defined %}
102+
report_interval: {{ nginx_agent_app_protect['report_interval'] }}
103+
{% endif %}
104+
{% if nginx_agent_app_protect['precompiled_publication'] is defined and nginx_agent_app_protect['precompiled_publication'] is boolean %}
105+
precompiled_publication: {{ nginx_agent_app_protect['precompiled_publication'] | ternary('true', 'false') }}
106+
{% endif %}
107+
{% endif %}
108+
109+
{% if nginx_agent_api is defined and nginx_agent_api is mapping %}
110+
api:
111+
{% if nginx_agent_api['host'] is defined %}
112+
host: {{ nginx_agent_api['host'] }}
113+
{% endif %}
114+
{% if nginx_agent_api['port'] is defined %}
115+
port: {{ nginx_agent_api['port'] }}
116+
{% endif %}
117+
{% if nginx_agent_api['cert'] is defined %}
118+
cert: {{ nginx_agent_api['cert'] }}
119+
{% endif %}
120+
{% if nginx_agent_api['key'] is defined %}
121+
key: {{ nginx_agent_api['key'] }}
122+
{% endif %}
123+
{% endif %}

0 commit comments

Comments
 (0)