Merge pull request #154 from M2Mobi/server_config_lists

Fix multiple values for the same key (include/listen) in server config file
This commit is contained in:
Niels Abspoel 2019-02-19 23:06:31 +01:00 committed by GitHub
commit 5006a2a8aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 14 deletions

View File

@ -2,17 +2,17 @@
{%- macro server_config(values, key='', ind=0, lb='\n', delim=';', operator=' ') -%} {%- macro server_config(values, key='', ind=0, lb='\n', delim=';', operator=' ') -%}
{%- for value in values -%} {%- for value in values -%}
{%- if value is number or value is string -%} {%- if value is number or value is string -%}
{{ lb }}{{ key|indent(ind, True) }}{{ operator }}{{ value }}{{ delim }} {{ key|indent(ind, True) }}{{ operator }}{{ value }}{{ delim }}{{ lb }}
{%- elif value is mapping -%} {%- elif value is mapping -%}
{%- for k, v in value.items() -%} {%- for k, v in value.items() -%}
{%- if v is number or v is string -%} {%- if v is number or v is string -%}
{{ server_config([v], k, ind) }} {{ server_config([v], k, ind) }}
{%- elif v|length() > 0 and (v[0] is number or v[0] is string) -%} {%- elif v|length() > 0 and (v[0] is number or v[0] is string) -%}
{{ lb }}{{ k|indent(ind,True) }}{{ server_config(v,'', 0, '', '')}}{{ delim }} {{ server_config(v, k, ind) }}
{%- else %} {%- else -%}
{{ lb }}{{ k|indent(ind, True) }} {{ '{' }} {{ lb }}{{ k|indent(ind, True) }} {{ '{' }}
{{- server_config(v, '', ind + ind_increment) }} {{ server_config(v, '', ind + ind_increment) -}}
{{ '}'|indent(ind, True) }} {{ '}'|indent(ind, True) }}{{ lb }}
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
{%- elif value is iterable -%} {%- elif value is iterable -%}

View File

@ -201,28 +201,40 @@ nginx:
- server: - server:
- server_name: localhost - server_name: localhost
- listen: - listen:
- 80 - '80 default_server'
- default_server - listen:
- index: - '443 ssl'
- index.html - index: 'index.html index.htm'
- index.htm
- location ~ .htm: - location ~ .htm:
- try_files: - try_files: '$uri $uri/ =404'
- $uri
- $uri/ =404
- test: something else - test: something else
- include 'snippets/letsencrypt.conf' - include 'snippets/letsencrypt.conf'
# The above outputs: # Or a slightly more compact alternative syntax:
- server:
- server_name: localhost
- listen:
- '80 default_server'
- '443 ssl'
- index: 'index.html index.htm'
- location ~ .htm:
- try_files: '$uri $uri/ =404'
- test: something else
- include 'snippets/letsencrypt.conf'
# both of those output:
# server { # server {
# server_name localhost; # server_name localhost;
# listen 80 default_server; # listen 80 default_server;
# listen 443 ssl;
# index index.html index.htm; # index index.html index.htm;
# location ~ .htm { # location ~ .htm {
# try_files $uri $uri/ =404; # try_files $uri $uri/ =404;
# test something else; # test something else;
# } # }
# } # }
mysite2: # Using source_path options to upload the file instead of templating all the file mysite2: # Using source_path options to upload the file instead of templating all the file
enabled: True enabled: True
available_dir: /etc/nginx/sites-available available_dir: /etc/nginx/sites-available