vhost: move variable definition from set_fact to vars
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
# yamllint disable rule:line-length
|
||||
block: |
|
||||
{{ vhost_domains | join(' ') }} {
|
||||
{% for location in vhost_locations_all %}
|
||||
{% for location in _vhost_locations_complete %}
|
||||
handle {{ location.path }} {
|
||||
{% for header in location.delete_headers %}
|
||||
header -{{ header }}
|
||||
|
||||
@@ -14,40 +14,6 @@
|
||||
- vhost_redirect_preserve_path
|
||||
- vhost_redirect_target.endswith('/')
|
||||
|
||||
- name: Reset vhost_locations_all
|
||||
ansible.builtin.set_fact:
|
||||
vhost_locations_all: []
|
||||
- name: Set vhost_locations_all reverse proxies
|
||||
ansible.builtin.set_fact:
|
||||
vhost_locations_all: >
|
||||
{{ vhost_locations_all + [{
|
||||
'path': item.path,
|
||||
'type': item.type | default(vhost_type),
|
||||
'headers': item.headers | default(vhost_headers),
|
||||
'delete_headers': item.delete_headers | default(vhost_delete_headers),
|
||||
|
||||
'basicauth': item.basicauth | default(vhost_basicauth),
|
||||
'basicauth_users': item.basicauth_users | default(vhost_basicauth_users),
|
||||
|
||||
'proxy_target_netproto': item.proxy_target_netproto | default(vhost_proxy_target_netproto),
|
||||
'proxy_target_protocol': item.proxy_target_protocol | default(vhost_proxy_target_protocol),
|
||||
'proxy_target_host': item.proxy_target_host | default(vhost_proxy_target_host),
|
||||
'proxy_target_port': item.proxy_target_port | default(vhost_proxy_target_port if
|
||||
vhost_type == 'reverse_proxy' and vhost_proxy_target_netproto == 'tcp' else ''),
|
||||
'proxy_target_socket': item.proxy_target_socket | default(vhost_proxy_target_socket if
|
||||
vhost_type == 'reverse_proxy' and vhost_proxy_target_netproto == 'unix' else ''),
|
||||
'proxy_delete_headers': item.proxy_delete_headers | default(vhost_proxy_delete_headers),
|
||||
|
||||
'redirect_target': item.redirect_target | default(vhost_redirect_target if vhost_type == 'redirect' else ''),
|
||||
'redirect_preserve_path': item.redirect_preserve_path | default(vhost_redirect_preserve_path),
|
||||
'redirect_preserve_query': item.redirect_preserve_query | default(vhost_redirect_preserve_query),
|
||||
'redirect_type': item.redirect_type | default(vhost_redirect_type),
|
||||
|
||||
'respond_content': item.respond_content | default(vhost_respond_content if vhost_type == 'respond' else ''),
|
||||
'respond_content_type': item.respond_content_type | default(vhost_respond_content_type)
|
||||
}] }}
|
||||
loop: "{{ vhost_locations + [{'path': ''}] }}"
|
||||
|
||||
- name: "Setup {{ vhost_id + ' vhost on ' + vhost_web_server }}"
|
||||
ansible.builtin.include_tasks: "{{ vhost_web_server }}.yaml"
|
||||
when: vhost_web_server != 'none'
|
||||
|
||||
34
roles/vhost/vars/main.yaml
Normal file
34
roles/vhost/vars/main.yaml
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
_vhost_location_defaults:
|
||||
type: "{{ vhost_type }}"
|
||||
headers: "{{ vhost_headers }}"
|
||||
delete_headers: "{{ vhost_delete_headers }}"
|
||||
|
||||
basicauth: "{{ vhost_basicauth }}"
|
||||
basicauth_users: "{{ vhost_basicauth_users }}"
|
||||
|
||||
proxy_target_netproto: "{{ vhost_proxy_target_netproto }}"
|
||||
proxy_target_protocol: "{{ vhost_proxy_target_protocol }}"
|
||||
proxy_target_host: "{{ vhost_proxy_target_host }}"
|
||||
proxy_target_port: "{{ vhost_proxy_target_port if
|
||||
vhost_type == 'reverse_proxy' and vhost_proxy_target_netproto == 'tcp' else '' }}"
|
||||
proxy_target_socket: "{{ vhost_proxy_target_socket if
|
||||
vhost_type == 'reverse_proxy' and vhost_proxy_target_netproto == 'unix' else '' }}"
|
||||
proxy_delete_headers: "{{ vhost_proxy_delete_headers }}"
|
||||
|
||||
redirect_target: "{{ vhost_redirect_target if vhost_type == 'redirect' else '' }}"
|
||||
redirect_preserve_path: "{{ vhost_redirect_preserve_path }}"
|
||||
redirect_preserve_query: "{{ vhost_redirect_preserve_query }}"
|
||||
redirect_type: "{{ vhost_redirect_type }}"
|
||||
|
||||
respond_content: "{{ vhost_respond_content if vhost_type == 'respond' else '' }}"
|
||||
respond_content_type: "{{ vhost_respond_content_type }}"
|
||||
|
||||
_vhost_locations: "{{ vhost_locations + [{'path': ''}] }}"
|
||||
|
||||
_vhost_locations_complete: "{{
|
||||
_vhost_locations
|
||||
| map('combine', _vhost_location_defaults)
|
||||
| zip(_vhost_locations)
|
||||
| map('combine')
|
||||
}}"
|
||||
Reference in New Issue
Block a user