vhost: Prefix variables with role name
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
Deprecated
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
reverse_proxy_type: caddy
|
|
||||||
web_server: "{{ reverse_proxy_type }}"
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
- name: Deprecation warning
|
|
||||||
ansible.builtin.debug:
|
|
||||||
msg: "uumas.general.reverse_proxy is deprecated. You should switch to uumas.general.vhost with vhost_type: reverse_proxy"
|
|
||||||
|
|
||||||
- name: Legacy proxy_target handling
|
|
||||||
when: proxy_target is defined and proxy_target_port is not defined
|
|
||||||
block:
|
|
||||||
- name: Split legacy proxy_target to protocol and target
|
|
||||||
ansible.builtin.set_fact:
|
|
||||||
proxy_target_split_protocol: "{{ proxy_target.split('://') }}"
|
|
||||||
- name: Split target further to host and port
|
|
||||||
ansible.builtin.set_fact:
|
|
||||||
proxy_target_split_host: "{{ (proxy_target_split_protocol | last).split(':') }}"
|
|
||||||
- name: Set host and port variables
|
|
||||||
ansible.builtin.set_fact:
|
|
||||||
proxy_target_host: "{{ proxy_target_split_host[0] }}"
|
|
||||||
proxy_target_port: "{{ proxy_target_split_host[1] }}"
|
|
||||||
|
|
||||||
- name: Set proxy_target_protocol based on proxy_target
|
|
||||||
ansible.builtin.set_fact:
|
|
||||||
proxy_target_protocol: "{{ proxy_target_split_protocol[0] }}"
|
|
||||||
when: proxy_target_split_protocol | length == 2
|
|
||||||
|
|
||||||
- name: Configure vhost for reverse proxy
|
|
||||||
ansible.builtin.include_role:
|
|
||||||
name: vhost
|
|
||||||
vars:
|
|
||||||
vhost_type: reverse_proxy
|
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
vhost_state: present
|
vhost_state: present
|
||||||
vhost_type: "{{ vhost_state }}"
|
vhost_type: "{{ vhost_state }}"
|
||||||
vhost_domains: []
|
vhost_domains: []
|
||||||
web_server: caddy
|
vhost_web_server: caddy
|
||||||
|
|
||||||
vhost_locations: []
|
vhost_locations: []
|
||||||
vhost_headers: {}
|
vhost_headers: {}
|
||||||
@@ -12,11 +12,11 @@ vhost_delete_headers: []
|
|||||||
vhost_basicauth: false
|
vhost_basicauth: false
|
||||||
vhost_basicauth_users: {}
|
vhost_basicauth_users: {}
|
||||||
|
|
||||||
proxy_target_protocol: http
|
vhost_proxy_target_protocol: http
|
||||||
proxy_target_host: localhost
|
vhost_proxy_target_host: localhost
|
||||||
proxy_delete_headers: []
|
vhost_proxy_delete_headers: []
|
||||||
|
|
||||||
redirect_type: temporary
|
vhost_redirect_type: temporary
|
||||||
redirect_preserve_path: false
|
vhost_redirect_preserve_path: false
|
||||||
|
|
||||||
respond_content_type: plain
|
vhost_respond_content_type: plain
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
argument_specs:
|
argument_specs:
|
||||||
main:
|
main:
|
||||||
short_description: Sets up a vhost
|
short_description: Sets up a vhost
|
||||||
|
description:
|
||||||
|
- Sets up a vhost on a web server.
|
||||||
|
- Supports reverse proxies, redirects and simple resonses.
|
||||||
|
- Currently only supports caddy.
|
||||||
options:
|
options:
|
||||||
vhost_id:
|
vhost_id:
|
||||||
description: A unique identifier for this vhost. Not visible to end users.
|
description: A unique identifier for this vhost. Not visible to end users.
|
||||||
@@ -28,8 +31,8 @@ argument_specs:
|
|||||||
type: list
|
type: list
|
||||||
required: "{{ vhost_state == 'present' }}"
|
required: "{{ vhost_state == 'present' }}"
|
||||||
elements: str
|
elements: str
|
||||||
web_server:
|
vhost_web_server:
|
||||||
description: Defines which server software to use for vhost. This role does nothing if set to none
|
description: Defines which server software to use for vhost. This role does nothing if set to none.
|
||||||
type: str
|
type: str
|
||||||
required: false
|
required: false
|
||||||
default: caddy
|
default: caddy
|
||||||
@@ -59,16 +62,16 @@ argument_specs:
|
|||||||
required: false
|
required: false
|
||||||
default: {}
|
default: {}
|
||||||
|
|
||||||
proxy_target_port:
|
vhost_proxy_target_port:
|
||||||
description: Port where to proxy requests to. Only applicable if vhost_type is reverse_proxy
|
description: Port where to proxy requests to. Only applicable if vhost_type is reverse_proxy
|
||||||
type: int
|
type: int
|
||||||
required: "{{ vhost_state == 'present' and vhost_type == 'reverse_proxy' }}"
|
required: "{{ vhost_state == 'present' and vhost_type == 'reverse_proxy' }}"
|
||||||
proxy_target_host:
|
vhost_proxy_target_host:
|
||||||
description: Host where to proxy requests to. Only applicable if vhost_type is reverse_proxy
|
description: Host where to proxy requests to. Only applicable if vhost_type is reverse_proxy
|
||||||
type: str
|
type: str
|
||||||
required: false
|
required: false
|
||||||
default: localhost
|
default: localhost
|
||||||
proxy_target_protocol:
|
vhost_proxy_target_protocol:
|
||||||
description: Protocol to use for proxy requests. Only applicable if vhost_type is reverse_proxy
|
description: Protocol to use for proxy requests. Only applicable if vhost_type is reverse_proxy
|
||||||
type: str
|
type: str
|
||||||
required: false
|
required: false
|
||||||
@@ -76,18 +79,18 @@ argument_specs:
|
|||||||
choices:
|
choices:
|
||||||
- http
|
- http
|
||||||
- https
|
- https
|
||||||
proxy_delete_headers:
|
vhost_proxy_delete_headers:
|
||||||
description: List of headers to delete from proxied requests
|
description: List of headers to delete from proxied requests
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
required: false
|
required: false
|
||||||
default: []
|
default: []
|
||||||
|
|
||||||
redirect_target:
|
vhost_redirect_target:
|
||||||
description: "Only applicable if vhost_type is redirect. Example: https://www.domain.tld/location"
|
description: "Only applicable if vhost_type is redirect. Example: https://www.domain.tld/location"
|
||||||
type: str
|
type: str
|
||||||
required: "{{ vhost_state == 'present' and vhost_type == 'redirect' }}"
|
required: "{{ vhost_state == 'present' and vhost_type == 'redirect' }}"
|
||||||
redirect_preserve_path:
|
vhost_redirect_preserve_path:
|
||||||
description: Whether to keep the original request path
|
description: Whether to keep the original request path
|
||||||
type: bool
|
type: bool
|
||||||
required: false
|
required: false
|
||||||
@@ -101,11 +104,11 @@ argument_specs:
|
|||||||
- temporary
|
- temporary
|
||||||
- permanent
|
- permanent
|
||||||
|
|
||||||
respond_content:
|
vhost_respond_content:
|
||||||
description: Content to respond with. Json content can be set as yaml as long as respond_content_type is set to json
|
description: Content to respond with. Json content can be set as yaml as long as vhost_respond_content_type is set to json
|
||||||
type: str
|
type: str
|
||||||
required: "{{ vhost_state == 'present' and vhost_type == 'respond' }}"
|
required: "{{ vhost_state == 'present' and vhost_type == 'respond' }}"
|
||||||
respond_content_type:
|
vhost_respond_content_type:
|
||||||
description: Type of the respond content
|
description: Type of the respond content
|
||||||
type: str
|
type: str
|
||||||
required: false
|
required: false
|
||||||
@@ -159,17 +162,17 @@ argument_specs:
|
|||||||
description: Port where to proxy requests to. Only applicable if type is reverse_proxy.
|
description: Port where to proxy requests to. Only applicable if type is reverse_proxy.
|
||||||
type: int
|
type: int
|
||||||
required: false
|
required: false
|
||||||
default: "{{ proxy_target_port if vhost_type == 'reverse_proxy' else 0 }}"
|
default: "{{ vhost_proxy_target_port if vhost_type == 'reverse_proxy' else 0 }}"
|
||||||
proxy_target_host:
|
proxy_target_host:
|
||||||
description: Host where to proxy requests to. Only applicable if type is reverse_proxy
|
description: Host where to proxy requests to. Only applicable if type is reverse_proxy
|
||||||
type: str
|
type: str
|
||||||
required: false
|
required: false
|
||||||
default: "{{ proxy_target_host }}"
|
default: "{{ vhost_proxy_target_host }}"
|
||||||
proxy_target_protocol:
|
proxy_target_protocol:
|
||||||
description: Protocol to use for proxy requests. Only applicable if type is reverse_proxy
|
description: Protocol to use for proxy requests. Only applicable if type is reverse_proxy
|
||||||
type: str
|
type: str
|
||||||
required: false
|
required: false
|
||||||
default: "{{ proxy_target_protocol }}"
|
default: "{{ vhost_proxy_target_protocol }}"
|
||||||
choices:
|
choices:
|
||||||
- http
|
- http
|
||||||
- https
|
- https
|
||||||
@@ -178,23 +181,23 @@ argument_specs:
|
|||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
required: false
|
required: false
|
||||||
default: "{{ proxy_delete_headers }}"
|
default: "{{ vhost_proxy_delete_headers }}"
|
||||||
|
|
||||||
redirect_target:
|
redirect_target:
|
||||||
description: "Only applicable if vhost_type is redirect. Example: https://www.domain.tld/location"
|
description: "Only applicable if vhost_type is redirect. Example: https://www.domain.tld/location"
|
||||||
type: str
|
type: str
|
||||||
required: false
|
required: false
|
||||||
default: "{{ redirect_target if vhost_type == 'redirect' else '' }}"
|
default: "{{ vhost_redirect_target if vhost_type == 'redirect' else '' }}"
|
||||||
redirect_preserve_path:
|
redirect_preserve_path:
|
||||||
description: Whether to keep the original request path
|
description: Whether to keep the original request path
|
||||||
type: bool
|
type: bool
|
||||||
required: false
|
required: false
|
||||||
default: "{{ redirect_preserve_path }}"
|
default: "{{ vhost_redirect_preserve_path }}"
|
||||||
redirect type:
|
redirect_type:
|
||||||
description: Only applicable if vhost_type is reverse_proxy
|
description: Only applicable if vhost_type is reverse_proxy
|
||||||
type: str
|
type: str
|
||||||
required: false
|
required: false
|
||||||
default: "{{ redirect_type }}"
|
default: "{{ vhost_redirect_type }}"
|
||||||
choices:
|
choices:
|
||||||
- temporary
|
- temporary
|
||||||
- permanent
|
- permanent
|
||||||
@@ -203,12 +206,12 @@ argument_specs:
|
|||||||
description: Content to respond with. Json content can be set as yaml as long as respond_content_type is set to json
|
description: Content to respond with. Json content can be set as yaml as long as respond_content_type is set to json
|
||||||
type: str
|
type: str
|
||||||
required: false
|
required: false
|
||||||
default: "{{ respond_content if vhost_type == 'respond' else '' }}"
|
default: "{{ vhost_respond_content if vhost_type == 'respond' else '' }}"
|
||||||
respond_content_type:
|
respond_content_type:
|
||||||
description: Type of the respond content
|
description: Type of the respond content
|
||||||
type: str
|
type: str
|
||||||
required: false
|
required: false
|
||||||
default: "{{ respond_content_type }}"
|
default: "{{ vhost_respond_content_type }}"
|
||||||
choices:
|
choices:
|
||||||
- plain
|
- plain
|
||||||
- json
|
- json
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
- role: caddy
|
- role: caddy
|
||||||
when: web_server == 'caddy'
|
when: vhost_web_server == 'caddy'
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: Fail if redirect_target is a relative path and redirect_preserve_path is true
|
- name: Fail if vhost_redirect_target is a relative path and vhost_redirect_preserve_path is true
|
||||||
ansible.builtin.fail:
|
ansible.builtin.fail:
|
||||||
msg: redirect_target must be an absolute url or absolute path if redirect_preserve_path is true
|
msg: vhost_redirect_target must be an absolute url or absolute path if vhost_redirect_preserve_path is true
|
||||||
when:
|
when:
|
||||||
- redirect_preserve_path
|
- vhost_redirect_preserve_path
|
||||||
- redirect_target.split('://') | length < 2
|
- vhost_redirect_target.split('://') | length < 2
|
||||||
- not redirect_target.startswith('/')
|
- not vhost_redirect_target.startswith('/')
|
||||||
|
|
||||||
- name: Fail if redirect_target ends with / and redirect_preserve_path is true
|
- name: Fail if vhost_redirect_target ends with / and vhost_redirect_preserve_path is true
|
||||||
ansible.builtin.fail:
|
ansible.builtin.fail:
|
||||||
msg: redirect_target must not end with / if redirect_preserve_path is true
|
msg: vhost_redirect_target must not end with / if vhost_redirect_preserve_path is true
|
||||||
when:
|
when:
|
||||||
- redirect_preserve_path
|
- vhost_redirect_preserve_path
|
||||||
- redirect_target.endswith('/')
|
- vhost_redirect_target.endswith('/')
|
||||||
|
|
||||||
- name: Reset vhost_locations_all
|
- name: Reset vhost_locations_all
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
@@ -30,20 +30,20 @@
|
|||||||
'basicauth': item.basicauth | default(vhost_basicauth),
|
'basicauth': item.basicauth | default(vhost_basicauth),
|
||||||
'basicauth_users': item.basicauth_users | default(vhost_basicauth_users),
|
'basicauth_users': item.basicauth_users | default(vhost_basicauth_users),
|
||||||
|
|
||||||
'proxy_target_port': item.proxy_target_port | default(proxy_target_port if vhost_type == 'reverse_proxy' else ''),
|
'proxy_target_port': item.proxy_target_port | default(vhost_proxy_target_port if vhost_type == 'reverse_proxy' else ''),
|
||||||
'proxy_target_host': item.proxy_target_host | default(proxy_target_host),
|
'proxy_target_host': item.proxy_target_host | default(vhost_proxy_target_host),
|
||||||
'proxy_target_protocol': item.proxy_target_protocol | default(proxy_target_protocol),
|
'proxy_target_protocol': item.proxy_target_protocol | default(vhost_proxy_target_protocol),
|
||||||
'proxy_delete_headers': item.proxy_delete_headers | default(proxy_delete_headers),
|
'proxy_delete_headers': item.proxy_delete_headers | default(vhost_proxy_delete_headers),
|
||||||
|
|
||||||
'redirect_target': item.redirect_target | default(redirect_target if vhost_type == 'redirect' else ''),
|
'redirect_target': item.redirect_target | default(vhost_redirect_target if vhost_type == 'redirect' else ''),
|
||||||
'redirect_preserve_path': item.redirect_preserve_path | default(redirect_preserve_path),
|
'redirect_preserve_path': item.redirect_preserve_path | default(vhost_redirect_preserve_path),
|
||||||
'redirect_type': item.redirect_type | default(redirect_type),
|
'redirect_type': item.redirect_type | default(vhost_redirect_type),
|
||||||
|
|
||||||
'respond_content': item.respond_content | default(respond_content if vhost_type == 'respond' else ''),
|
'respond_content': item.respond_content | default(vhost_respond_content if vhost_type == 'respond' else ''),
|
||||||
'respond_content_type': item.respond_content_type | default(respond_content_type)
|
'respond_content_type': item.respond_content_type | default(vhost_respond_content_type)
|
||||||
}] }}
|
}] }}
|
||||||
loop: "{{ vhost_locations + [{'path': ''}] }}"
|
loop: "{{ vhost_locations + [{'path': ''}] }}"
|
||||||
|
|
||||||
- name: "Setup {{ vhost_id + ' vhost on ' + web_server }}"
|
- name: "Setup {{ vhost_id + ' vhost on ' + vhost_web_server }}"
|
||||||
ansible.builtin.include_tasks: "{{ web_server }}.yml"
|
ansible.builtin.include_tasks: "{{ vhost_web_server }}.yml"
|
||||||
when: web_server != 'none'
|
when: vhost_web_server != 'none'
|
||||||
|
|||||||
Reference in New Issue
Block a user