From 42f776f7d8e49667442622cd66aaeaca94899ef3 Mon Sep 17 00:00:00 2001 From: Zeno Grandi Date: Wed, 17 Jul 2019 13:32:47 +0200 Subject: [PATCH] Support for 'include' directive in http templating (#160) * Added 'include' directive in http templating * Added 'include' directive in stream templating --- README.md | 4 ++++ defaults/main.yml | 4 ++++ templates/http/default.conf.j2 | 15 +++++++++++++++ templates/stream/default.conf.j2 | 5 +++++ 4 files changed, 28 insertions(+) diff --git a/README.md b/README.md index 43c1954..38786ca 100644 --- a/README.md +++ b/README.md @@ -360,6 +360,7 @@ nginx_http_template: conf_file_location: /etc/nginx/conf.d/ port: 8081 server_name: localhost + include_files: [] error_page: /usr/share/nginx/html root: /usr/share/nginx/html https_redirect: false @@ -399,6 +400,7 @@ nginx_http_template: locations: default: location: / + include_files: [] proxy_hide_headers: [] # A list of headers which shouldn't be passed to the application add_headers: strict_transport_security: @@ -448,6 +450,7 @@ nginx_http_template: locations: backend: location: / + include_files: [] proxy_hide_headers: [] # A list of headers which shouldn't be passed to the application add_headers: strict_transport_security: @@ -578,6 +581,7 @@ nginx_stream_template: listen_address: localhost listen_port: 80 udp_enable: false + include_files: [] proxy_pass: backend proxy_timeout: 3s proxy_connect_timeout: 1s diff --git a/defaults/main.yml b/defaults/main.yml index 686fcb8..12aaa8e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -172,6 +172,7 @@ nginx_http_template: conf_file_location: /etc/nginx/conf.d/ port: 8081 server_name: localhost + include_files: [] error_page: /usr/share/nginx/html root: /usr/share/nginx/html https_redirect: false @@ -211,6 +212,7 @@ nginx_http_template: locations: default: location: / + include_files: [] proxy_hide_headers: [] # A list of headers which shouldn't be passed to the application add_headers: strict_transport_security: @@ -260,6 +262,7 @@ nginx_http_template: locations: backend: location: / + include_files: [] proxy_hide_headers: [] # A list of headers which shouldn't be passed to the application add_headers: strict_transport_security: @@ -390,6 +393,7 @@ nginx_stream_template: listen_address: localhost listen_port: 80 udp_enable: false + include_files: [] proxy_pass: backend proxy_timeout: 3s proxy_connect_timeout: 1s diff --git a/templates/http/default.conf.j2 b/templates/http/default.conf.j2 index ff32f40..f016732 100644 --- a/templates/http/default.conf.j2 +++ b/templates/http/default.conf.j2 @@ -91,6 +91,11 @@ server { listen {{ item.value.port }}; {% endif %} server_name {{ item.value.server_name | default('localhost') }}; +{% if item.value.include_files is defined and item.value.include_files | length %} +{% for file in item.value.include_files %} + include "{{ file }}"; +{% endfor %} +{% endif %} {% if item.value.proxy_hide_headers is defined %} {% for header in item.value.proxy_hide_headers %} proxy_hide_header {{ header }}; @@ -135,6 +140,11 @@ server { {% if item.value.reverse_proxy.locations[location].internal is sameas true %} internal; {% endif %} +{% if item.value.reverse_proxy.locations[location].include_files is defined and item.value.reverse_proxy.locations[location].include_files | length %} +{% for file in item.value.reverse_proxy.locations[location].include_files %} + include "{{ file }}"; +{% endfor %} +{% endif %} {% if item.value.reverse_proxy.locations[location].proxy_hide_headers is defined %} {% for header in item.value.reverse_proxy.locations[location].proxy_hide_headers %} proxy_hide_header {{ header }}; @@ -289,6 +299,11 @@ server { {% if item.value.web_server.locations[location].try_files is defined %} try_files {{ item.value.web_server.locations[location].try_files }}; {% endif %} +{% if item.value.web_server.locations[location].include_files is defined and item.value.web_server.locations[location].include_files | length %} +{% for file in item.value.web_server.locations[location].include_files %} + include "{{ file }}"; +{% endfor %} +{% endif %} {% if item.value.web_server.locations[location].proxy_hide_headers is defined %} {% for header in item.value.web_server.locations[location].proxy_hide_headers %} proxy_hide_header {{ header }}; diff --git a/templates/stream/default.conf.j2 b/templates/stream/default.conf.j2 index 3f1fcb2..048dbc7 100644 --- a/templates/stream/default.conf.j2 +++ b/templates/stream/default.conf.j2 @@ -42,6 +42,11 @@ server { {% else %} listen {{ item.value.network_streams[stream].listen_port }}; {% endif %} +{% endif %} +{% if item.value.network_streams[stream].include_files is defined and item.value.network_streams[stream].include_files | length %} +{% for file in item.value.network_streams[stream].include_files %} + include "{{ file }}"; +{% endfor %} {% endif %} proxy_pass {{ item.value.network_streams[stream].proxy_pass }}; proxy_timeout {{ item.value.network_streams[stream].proxy_timeout }};