Support deleting vhosts

This commit is contained in:
uumas
2024-07-28 00:45:20 +03:00
parent 9a94786bec
commit 1dbb9eac4c
3 changed files with 18 additions and 5 deletions

View File

@@ -1,5 +1,8 @@
--- ---
vhost_state: present
vhost_type: "{{ vhost_state }}"
vhost_domains: []
web_server: caddy web_server: caddy
vhost_locations: [] vhost_locations: []

View File

@@ -8,16 +8,25 @@ argument_specs:
description: A unique identifier for this vhost. Not visible to end users. description: A unique identifier for this vhost. Not visible to end users.
type: str type: str
required: true required: true
vhost_state:
description: Whether the vhost should exist or not
type: str
required: false
default: present
choices:
- present
- absent
vhost_type: vhost_type:
type: str type: str
required: true required: "{{ vhost_state == 'present' }}"
choices: choices:
- reverse_proxy - reverse_proxy
- redirect - redirect
- respond - respond
- absent
vhost_domains: vhost_domains:
type: list type: list
required: true required: "{{ vhost_state == 'present' }}"
elements: str elements: str
web_server: 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
@@ -47,7 +56,7 @@ argument_specs:
proxy_target_port: 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_type == 'reverse_proxy' }}" required: "{{ vhost_state == 'present' and vhost_type == 'reverse_proxy' }}"
proxy_target_host: 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
@@ -65,7 +74,7 @@ argument_specs:
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: "{{ vhost_type == 'redirect' }}" required: "{{ vhost_state == 'present' and vhost_type == 'redirect' }}"
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
@@ -83,7 +92,7 @@ argument_specs:
respond_content: 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 respond_content_type is set to json
type: str type: str
required: "{{ vhost_type == 'respond' }}" required: "{{ vhost_state == 'present' and vhost_type == 'respond' }}"
respond_content_type: respond_content_type:
description: Type of the respond content description: Type of the respond content
type: str type: str

View File

@@ -40,4 +40,5 @@
} }
validate: 'caddy validate --config %s --adapter caddyfile' validate: 'caddy validate --config %s --adapter caddyfile'
backup: true backup: true
state: "{{ vhost_state }}"
notify: Reload caddy notify: Reload caddy