Use macro for auth_basic

pull/14/head
Emilien Mantel 2015-12-03 16:59:37 +01:00
parent c0f2d694e7
commit 88d1c7fdb7
1 changed files with 7 additions and 5 deletions

View File

@ -1,6 +1,12 @@
{% set __listen = item.listen | default(['80']) %} {% set __listen = item.listen | default(['80']) %}
{% set __listen_ssl = item.listen_ssl | default(['443']) %} {% set __listen_ssl = item.listen_ssl | default(['443']) %}
{% set __location = item.location | default({}) %} {% set __location = item.location | default({}) %}
{% macro htpasswd(htpasswd_name, indent=2) -%}
{% for ht in nginx_htpasswd %}{% if ht.name == htpasswd_name %}
{{ "\t" * indent }}auth_basic "{{ ht.description }}";
{{ "\t" * indent }}auth_basic_user_file {{ nginx_htpasswd_dir }}/{{ ht.name }};
{% endif %}{% endfor%}
{%- endmacro %}
# #
# {{ ansible_managed }} # {{ ansible_managed }}
# #
@ -67,11 +73,7 @@ server {
{% for location, opts in __location.iteritems() %} {% for location, opts in __location.iteritems() %}
location {{ location }} { location {{ location }} {
{% for opt in opts %} {% for opt in opts %}
{% if opt.htpasswd is defined %}{% for ht in nginx_htpasswd %}{% if ht.name == opt.htpasswd %} {% if opt.htpasswd is defined %}{{ htpasswd(opt.htpasswd, 2) }}{% else %}
auth_basic "{{ ht.description }}";
auth_basic_user_file {{ nginx_htpasswd_dir }}/{{ opt.htpasswd }};
{% endif %}{% endfor %}
{% else %}
{{ opt }} {{ opt }}
{% endif %} {% endif %}
{% endfor %} {% endfor %}