diff --git a/README.md b/README.md index de937f2..782fca6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/defaults/main.yml b/defaults/main.yml index 6cf5aa1..919e29f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 diff --git a/tasks/conf/setup-rest-api.yml b/tasks/conf/setup-rest-api.yml deleted file mode 100644 index 4b6a63f..0000000 --- a/tasks/conf/setup-rest-api.yml +++ /dev/null @@ -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" diff --git a/tasks/conf/template-config.yml b/tasks/conf/template-config.yml index c6b06a4..5e97eef 100644 --- a/tasks/conf/template-config.yml +++ b/tasks/conf/template-config.yml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml index 4251a75..436a8ba 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 diff --git a/templates/api.conf.j2 b/templates/api.conf.j2 new file mode 100644 index 0000000..5fc4ffa --- /dev/null +++ b/templates/api.conf.j2 @@ -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 %} +} \ No newline at end of file