Refactor REST API deployment

This refactor should fix #17 and ensure that api.conf only gets created when rest_api_enable is set to true and that api.conf gets created in the correct location
This commit is contained in:
Alessandro Fael Garcia 2018-04-06 16:29:49 -07:00
parent 4fa9a51718
commit 6047a1107d
4 changed files with 23 additions and 27 deletions

View File

@ -31,14 +31,11 @@ amplify_key: null
# Default is false. # Default is false.
status_enable: false status_enable: false
# Enable NGINX Plus REST API and write access. # Enable NGINX Plus REST API, write access to the REST API, and NGINX Plus dashboard.
# Default is false. # Default is false.
rest_api_enable: false rest_api_enable: false
rest_api_write: false rest_api_write: false
rest_api_dashboard: false
# Enable NGINX Plus dashboard. REST API also needs to be enabled.
# Default is false.
dashboard: false
# Location of your NGINX Plus license in your local machine. # Location of your NGINX Plus license in your local machine.
# Default is the files folder within the NGINX Ansible role. # Default is the files folder within the NGINX Ansible role.
@ -63,8 +60,8 @@ main_template_user: nginx
main_template_worker_processes: auto main_template_worker_processes: auto
main_template_error_level: warn main_template_error_level: warn
main_template_worker_connections: 1024 main_template_worker_connections: 1024
main_template_keepalive_timeout: 65
http_template_enable: false http_template_enable: false
http_template_keepalive_timeout: 65
http_template_listen: 80 http_template_listen: 80
http_template_server_name: localhost http_template_server_name: localhost
stream_template_enable: false stream_template_enable: false

View File

@ -1,6 +1,22 @@
--- ---
- name: "(Setup: NGINX Plus) Setup NGINX Plus API" - name: "(Setup: NGINX Plus) Setup NGINX Plus API"
template: blockinfile:
src: api.conf.j2 path: "{{ (http_template_enable) | ternary('/etc/nginx/conf.d/http/api.conf','/etc/nginx/conf.d/api.conf') }}"
dest: "{{ (http_template_enable) | ternary('/etc/nginx/conf.d/http/api.conf','/etc/nginx/conf.d/api.conf') }}" create: yes
block: |
server {
listen 8080;
location /api {
{% if rest_api_write %}
api write=on;
{% else %}
api;
{% endif %}
}
{% if rest_api_dashboard %}
location = /dashboard.html {
root /usr/share/nginx/html;
}
{% endif %}
}
notify: "(Handler: All OSs) Reload NGINX" notify: "(Handler: All OSs) Reload NGINX"

View File

@ -1,17 +0,0 @@
{% if rest_api_enable %}
server {
listen 8080;
location /api {
{% if rest_api_write %}
api write=on;
{% else %}
api;
{% endif %}
}
{% if dashboard %}
location = /dashboard.html {
root /usr/share/nginx/html;
}
{% endif %}
}
{% endif %}

View File

@ -23,7 +23,7 @@ http {
sendfile on; sendfile on;
#tcp_nopush on; #tcp_nopush on;
keepalive_timeout {{ main_template_keepalive_timeout }}; keepalive_timeout {{ http_template_keepalive_timeout }};
#gzip on; #gzip on;