From df84780f02f1c184c7ae3e2ef16c59de94576cb5 Mon Sep 17 00:00:00 2001 From: Dmitriy Skopintsev <41194602+bigstinky86@users.noreply.github.com> Date: Tue, 27 Nov 2018 01:06:46 +0600 Subject: [PATCH] Enable autoindex in http, server and location namespaces (#75) * Added condition to use new autoindex variable * Added condition to use new autoindex variable for separate virtual hosts * Added global autoindex and autoindex for separate virutal hosts * Added autoindex enabling for virtual host namespace * Added autoindex enabling for virtual host namespace variable * Added autoindex for testing puprposes * Changed autoindex to false * Added autoindex for virtual host * Added autoindex ot readme file --- README.md | 3 +++ defaults/main.yml | 3 +++ templates/http/default.conf.j2 | 6 ++++++ templates/nginx.conf.j2 | 3 +++ tests/playbooks/nginx-template.yml | 2 ++ 5 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 0718f2f..4b592a2 100644 --- a/README.md +++ b/README.md @@ -312,6 +312,7 @@ nginx_main_template: rate_limit: false keyval: false stream_enable: false + http_global_autoindex: false # Enable creating dynamic templated NGINX HTTP configuration files. # Defaults will not produce a valid configuration. Instead they are meant to showcase @@ -327,6 +328,7 @@ nginx_http_template: port: 8081 server_name: localhost error_page: /usr/share/nginx/html + autoindex: false ssl: cert: ssl/default.crt key: ssl/default.key @@ -336,6 +338,7 @@ nginx_http_template: location: / html_file_location: /usr/share/nginx/html html_file_name: index.html + autoindex: false http_demo_conf: false load_balancer: locations: diff --git a/defaults/main.yml b/defaults/main.yml index 1f9b464..e65d7d1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -145,6 +145,7 @@ nginx_main_template: rate_limit: false keyval: false stream_enable: false + http_global_autoindex: false # Enable creating dynamic templated NGINX HTTP configuration files. # Defaults will not produce a valid configuration. Instead they are meant to showcase @@ -160,6 +161,7 @@ nginx_http_template: port: 8081 server_name: localhost error_page: /usr/share/nginx/html + autoindex: false ssl: cert: ssl/default.crt key: ssl/default.key @@ -169,6 +171,7 @@ nginx_http_template: location: / html_file_location: /usr/share/nginx/html html_file_name: index.html + autoindex: false http_demo_conf: false load_balancer: locations: diff --git a/templates/http/default.conf.j2 b/templates/http/default.conf.j2 index a7fe9f9..6b6ee77 100644 --- a/templates/http/default.conf.j2 +++ b/templates/http/default.conf.j2 @@ -23,6 +23,9 @@ server { listen {{ item.value.port }}; {% endif %} server_name {{ item.value.server_name }}; +{% if item.value.autoindex %} + autoindex on; +{% endif %} {% if item.value.load_balancer is defined %} {% for location in item.value.load_balancer.locations %} location {{ item.value.load_balancer.locations[location].location }} { @@ -43,6 +46,9 @@ server { location {{ item.value.web_server.locations[location].location }} { root {{ item.value.web_server.locations[location].html_file_location }}; index {{ item.value.web_server.locations[location].html_file_name }}; +{% if item.value.web_server.locations[location].autoindex %} + autoindex on; +{% endif %} } {% endfor %} {% if item.value.web_server.http_demo_conf %} diff --git a/templates/nginx.conf.j2 b/templates/nginx.conf.j2 index 3decb9d..88ba181 100644 --- a/templates/nginx.conf.j2 +++ b/templates/nginx.conf.j2 @@ -35,6 +35,9 @@ http { {% if nginx_main_template.http_settings.keyval %} keyval_zone zone={{nginx_main_template.http_settings.keyval.zone}}:32k state=one.keyval; keyval $arg_text $text zone=one; +{% endif %} +{% if nginx_main_template.http_global_autoindex %} + autoindex on; {% endif %} include /etc/nginx/conf.d/*.conf; } diff --git a/tests/playbooks/nginx-template.yml b/tests/playbooks/nginx-template.yml index daaea92..367cbbc 100644 --- a/tests/playbooks/nginx-template.yml +++ b/tests/playbooks/nginx-template.yml @@ -14,10 +14,12 @@ port: 80 server_name: localhost error_page: /usr/share/nginx/html + autoindex: false web_server: locations: default: location: / html_file_location: /usr/share/nginx/html html_file_name: index.html + autoindex: false http_demo_conf: false