Skip to content

Commit 1d30d42

Browse files
authored
Merge pull request #109 from downingar/api_file
Changing the API config to be a template
2 parents 6fa3668 + e0bbce9 commit 1d30d42

File tree

6 files changed

+28
-25
lines changed

6 files changed

+28
-25
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ nginx_status_port: 8080
426426
# Requires NGINX Plus.
427427
# Default is false.
428428
nginx_rest_api_enable: false
429+
nginx_rest_api_src: api.conf.j2
429430
nginx_rest_api_location: /etc/nginx/conf.d/api.conf
430431
nginx_rest_api_port: 8080
431432
nginx_rest_api_write: false

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ nginx_status_port: 8080
265265
# Requires NGINX Plus.
266266
# Default is false.
267267
nginx_rest_api_enable: false
268+
nginx_rest_api_src: api.conf.j2
268269
nginx_rest_api_location: /etc/nginx/conf.d/api.conf
269270
nginx_rest_api_port: 8080
270271
nginx_rest_api_write: false

tasks/conf/setup-rest-api.yml

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

tasks/conf/template-config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,11 @@
6464
with_dict: "{{ nginx_stream_template }}"
6565
when: nginx_stream_template_enable
6666
notify: "(Handler: All OSs) Reload NGINX"
67+
68+
- name: "(Setup: All NGINX) Dynamically Generate NGINX API Configuration File"
69+
template:
70+
src: "{{ nginx_rest_api_src }}"
71+
dest: "{{ nginx_rest_api_location }}"
72+
backup: yes
73+
notify: "(Handler: All OSs) Reload NGINX"
74+
when: nginx_rest_api_enable

tasks/main.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@
4444
when: nginx_main_template_enable
4545
or nginx_http_template_enable
4646
or nginx_stream_template_enable
47+
or nginx_rest_api_enable
4748

4849
- import_tasks: conf/setup-status.yml
4950
when: nginx_status_enable
5051

51-
- import_tasks: conf/setup-rest-api.yml
52-
when: nginx_rest_api_enable
53-
5452
- import_tasks: conf/debug-output.yml
5553
when: nginx_debug_output
5654

templates/api.conf.j2

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{ ansible_managed | comment }}
2+
3+
server {
4+
listen {{ nginx_rest_api_port }};
5+
location /api {
6+
{% if nginx_rest_api_write %}
7+
api write=on;
8+
{% else %}
9+
api;
10+
{% endif %}
11+
}
12+
{% if nginx_rest_api_dashboard %}
13+
location = /dashboard.html {
14+
root /usr/share/nginx/html;
15+
}
16+
{% endif %}
17+
}

0 commit comments

Comments
 (0)