Skip to content

Commit 3a519cf

Browse files
author
Akos Vandra
committed
made locations and try_files into arrays
1 parent aa6a854 commit 3a519cf

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

defaults/main.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,30 @@ nginx_sites:
1919
listen: 8080
2020
server_name: localhost
2121
root: "/tmp/site1"
22-
location1: {name: /, try_files: "$uri $uri/ /index.html"}
23-
location2: {name: /images/, try_files: "$uri $uri/ /index.html"}
22+
locations:
23+
- name: /
24+
try_files:
25+
- $uri
26+
- $uri/
27+
- /index.html
28+
- name: /images/
29+
try_files:
30+
- $uri
31+
- $uri/
32+
- /index.html
2433
- server:
2534
file_name: bar
2635
listen: 9090
2736
server_name: ansible
2837
root: "/tmp/site2"
29-
location1: {name: /, try_files: "$uri $uri/ /index.html"}
30-
location2: {name: /images/, try_files: "$uri $uri/ /index.html"}
38+
locations:
39+
- name: /
40+
try_files:
41+
- $uri
42+
- $uri/
43+
- /index.html
44+
- name: /images/
45+
try_files:
46+
- $uri
47+
- $uri/
48+
- /index.html

templates/site.j2

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ server {
66
{% endif %}
77

88
{% for k,v in item.server.iteritems() %}
9-
{% if k.find('location') == -1 and k != 'file_name' %}
9+
{% if k != 'locations' and k != 'file_name' %}
1010
{{ k }} {{ v }};
1111
{% endif %}
12-
{% endfor %}
12+
{% endfor %}
1313

14-
{% for k,v in item.server.iteritems() if k.find('location') != -1 %}
15-
location {{ v.name }} {
16-
{% for x,y in v.iteritems() if x != 'name' %}
17-
{{ x }} {{ y }};
14+
{% for loc in item.server.locations %}
15+
location {{ loc.name }} {
16+
{% for x,y in loc.iteritems() if x != 'name' %}
17+
{% if x == 'try_files' %}
18+
{{ x }} {{ y | join(' ')}};
19+
{% else %}
20+
{{ x }} {{ y }};
21+
{% endif %}
1822
{% endfor %}
1923
}
2024
{% endfor %}
2125
}
22-

0 commit comments

Comments
 (0)