Changing the API config to be a template

This commit is contained in:
Alan Downing 2019-02-28 14:27:18 -05:00
parent 6fa36689e7
commit e0bbce9b7f
6 changed files with 28 additions and 25 deletions

View File

@ -426,6 +426,7 @@ nginx_status_port: 8080
# Requires NGINX Plus.
# Default is false.
nginx_rest_api_enable: false
nginx_rest_api_src: api.conf.j2
nginx_rest_api_location: /etc/nginx/conf.d/api.conf
nginx_rest_api_port: 8080
nginx_rest_api_write: false

View File

@ -265,6 +265,7 @@ nginx_status_port: 8080
# Requires NGINX Plus.
# Default is false.
nginx_rest_api_enable: false
nginx_rest_api_src: api.conf.j2
nginx_rest_api_location: /etc/nginx/conf.d/api.conf
nginx_rest_api_port: 8080
nginx_rest_api_write: false

View File

@ -1,22 +0,0 @@
---
- name: "(Setup: NGINX Plus) Setup NGINX Plus API"
blockinfile:
path: "{{ nginx_rest_api_location }}"
create: yes
block: |
server {
listen {{ nginx_rest_api_port }};
location /api {
{% if nginx_rest_api_write %}
api write=on;
{% else %}
api;
{% endif %}
}
{% if nginx_rest_api_dashboard %}
location = /dashboard.html {
root /usr/share/nginx/html;
}
{% endif %}
}
notify: "(Handler: All OSs) Reload NGINX"

View File

@ -64,3 +64,11 @@
with_dict: "{{ nginx_stream_template }}"
when: nginx_stream_template_enable
notify: "(Handler: All OSs) Reload NGINX"
- name: "(Setup: All NGINX) Dynamically Generate NGINX API Configuration File"
template:
src: "{{ nginx_rest_api_src }}"
dest: "{{ nginx_rest_api_location }}"
backup: yes
notify: "(Handler: All OSs) Reload NGINX"
when: nginx_rest_api_enable

View File

@ -44,13 +44,11 @@
when: nginx_main_template_enable
or nginx_http_template_enable
or nginx_stream_template_enable
or nginx_rest_api_enable
- import_tasks: conf/setup-status.yml
when: nginx_status_enable
- import_tasks: conf/setup-rest-api.yml
when: nginx_rest_api_enable
- import_tasks: conf/debug-output.yml
when: nginx_debug_output

17
templates/api.conf.j2 Normal file
View File

@ -0,0 +1,17 @@
{{ ansible_managed | comment }}
server {
listen {{ nginx_rest_api_port }};
location /api {
{% if nginx_rest_api_write %}
api write=on;
{% else %}
api;
{% endif %}
}
{% if nginx_rest_api_dashboard %}
location = /dashboard.html {
root /usr/share/nginx/html;
}
{% endif %}
}