Compare commits
4 Commits
1340b825e1
...
5c5eff0370
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c5eff0370 | ||
|
|
d2313dbdf0 | ||
|
|
e27c8e8cf3 | ||
|
|
3974e6eb46 |
@@ -9,6 +9,6 @@ admin_email: 'admin@domain.tld'
|
||||
These variables are used by multiple roles and have the following default values:
|
||||
|
||||
```
|
||||
reverse_proxy_type: caddy # Allowed values: caddy, none
|
||||
web_server: caddy # Allowed values: caddy, none
|
||||
```
|
||||
|
||||
|
||||
44
docs/vhost.md
Normal file
44
docs/vhost.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Required variables
|
||||
These variables are required for this role to function. Example values provided
|
||||
|
||||
```
|
||||
vhost_id: myservice # A unique identifier for this vhost. Not visible to end users.
|
||||
vhost_type: reverse_proxy # Supported values: reverse_proxy, redirect
|
||||
vhost_domains:
|
||||
- www.domain.tld
|
||||
- domain.tld
|
||||
```
|
||||
|
||||
# Optional variables
|
||||
These variables have the following default values.
|
||||
|
||||
```
|
||||
web_server: caddy # Supported values: caddy, none
|
||||
```
|
||||
|
||||
# Variables specific to vhost type
|
||||
## reverse\_proxy
|
||||
|
||||
Required:
|
||||
```
|
||||
proxy_target_port: 8080
|
||||
```
|
||||
|
||||
Optional:
|
||||
```
|
||||
proxy_target_host: localhost
|
||||
proxy_target_protocol: http
|
||||
```
|
||||
|
||||
## redirect
|
||||
|
||||
Required:
|
||||
```
|
||||
redirect_target: https://www.domain.tld/location
|
||||
```
|
||||
|
||||
Optional:
|
||||
```
|
||||
redirect_type: temporary # Supported values: temporary, permanent
|
||||
```
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace: uumas
|
||||
name: general
|
||||
version: 0.5.4
|
||||
version: 0.5.5
|
||||
readme: README.md
|
||||
authors:
|
||||
- uumas
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
- debian-keyring
|
||||
- debian-archive-keyring
|
||||
- apt-transport-https
|
||||
update_cache: yes
|
||||
update_cache: true
|
||||
|
||||
- name: Add caddy repo signing key
|
||||
apt_key:
|
||||
@@ -30,7 +30,7 @@
|
||||
marker_end: '# https://caddyserver.com/docs/caddyfile'
|
||||
state: absent
|
||||
validate: 'caddy validate --config %s --adapter caddyfile'
|
||||
backup: yes
|
||||
backup: true
|
||||
|
||||
- name: Put caddy general config in place
|
||||
blockinfile:
|
||||
@@ -41,5 +41,5 @@
|
||||
email {{ admin_email }}
|
||||
}
|
||||
validate: 'caddy validate --config %s --adapter caddyfile'
|
||||
backup: yes
|
||||
backup: true
|
||||
notify: reload caddy
|
||||
|
||||
@@ -7,4 +7,3 @@ gen_locales:
|
||||
lang: en_US.UTF-8
|
||||
lc_messages: "{{ lang }}"
|
||||
language: "en_US:en"
|
||||
|
||||
|
||||
@@ -17,4 +17,4 @@
|
||||
template:
|
||||
src: locale.j2
|
||||
dest: "{{ locale_config }}"
|
||||
|
||||
mode: 0644
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
apt:
|
||||
name: "{{ install_packages }}"
|
||||
state: present
|
||||
update_cache: yes
|
||||
update_cache: true
|
||||
|
||||
- block:
|
||||
|
||||
- name: Enable backports
|
||||
apt_repository:
|
||||
repo: "deb http://deb.debian.org/debian {{ ansible_distribution_release }}-backports main"
|
||||
@@ -18,6 +17,4 @@
|
||||
name: "{{ backports_packages }}"
|
||||
state: present
|
||||
default_release: "{{ ansible_distribution_release }}-backports"
|
||||
|
||||
when: backports_packages is defined
|
||||
|
||||
|
||||
@@ -13,4 +13,3 @@
|
||||
name: "{{ delete_packages }}"
|
||||
state: absent
|
||||
when: delete_packages is defined
|
||||
|
||||
|
||||
@@ -4,4 +4,3 @@
|
||||
package:
|
||||
name: "{{ install_packages }}"
|
||||
state: present
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
Sets up a reverse proxy defined by the `reverse_proxy_type` variable
|
||||
Deprecated
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
|
||||
dependencies:
|
||||
- role: caddy
|
||||
when: reverse_proxy_type == 'caddy'
|
||||
@@ -1,12 +1,18 @@
|
||||
---
|
||||
|
||||
- name: Deprecation warning
|
||||
debug:
|
||||
msg: "uumas.general.reverse_proxy is deprecated. You should switch to uumas.general.vhost with vhost_type: reverse_proxy"
|
||||
|
||||
- block:
|
||||
- name: Split legacy proxy_target to protocol, host and port
|
||||
- name: Split legacy proxy_target to protocol and target
|
||||
set_fact:
|
||||
proxy_target_split_protocol: "{{ proxy_target.split('://') }}"
|
||||
- set_fact:
|
||||
- name: Split target further to host and port
|
||||
set_fact:
|
||||
proxy_target_split_host: "{{ (proxy_target_split_protocol | last).split(':') }}"
|
||||
- set_fact:
|
||||
- name: Set host and port variables
|
||||
set_fact:
|
||||
proxy_target_host: "{{ proxy_target_split_host[0] }}"
|
||||
proxy_target_port: "{{ proxy_target_split_host[1] }}"
|
||||
|
||||
@@ -14,9 +20,10 @@
|
||||
set_fact:
|
||||
proxy_target_protocol: "{{ proxy_target_split_protocol[0] }}"
|
||||
when: proxy_target_split_protocol | length == 2
|
||||
|
||||
when: proxy_target is defined and proxy_target_port is not defined
|
||||
|
||||
- name: Setup {{ vhost_id }} reverse proxy
|
||||
include_tasks: "{{ reverse_proxy_type }}.yml"
|
||||
when: reverse_proxy_type != 'none'
|
||||
- name: configure vhost for reverse proxy
|
||||
include_role:
|
||||
name: vhost
|
||||
vars:
|
||||
vhost_type: reverse_proxy
|
||||
|
||||
4
roles/reverse_proxy/vars/main.yml
Normal file
4
roles/reverse_proxy/vars/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
|
||||
reverse_proxy_type: caddy
|
||||
web_server: "{{ reverse_proxy_type }}"
|
||||
@@ -12,4 +12,3 @@
|
||||
PermitRootLogin: 'prohibit-password'
|
||||
PasswordAuthentication: "{{ 'yes' if sshd_password_auth else 'no' }}"
|
||||
X11Forwarding: "{{ 'yes' if sshd_x11_forwarding else 'no' }}"
|
||||
|
||||
|
||||
1
roles/vhost/README.md
Normal file
1
roles/vhost/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Sets up a vhost on web server defined by the `web_server` variable
|
||||
51
roles/vhost/meta/argument_specs.yml
Normal file
51
roles/vhost/meta/argument_specs.yml
Normal file
@@ -0,0 +1,51 @@
|
||||
---
|
||||
|
||||
argument_specs:
|
||||
main:
|
||||
short_description: Sets up a vhost
|
||||
options:
|
||||
vhost_id:
|
||||
description: A unique identifier for this vhost. Not visible to end users.
|
||||
type: str
|
||||
required: true
|
||||
vhost_type:
|
||||
type: str
|
||||
required: true
|
||||
choices:
|
||||
- reverse_proxy
|
||||
- redirect
|
||||
vhost_domains:
|
||||
type: list
|
||||
required: true
|
||||
elements: str
|
||||
web_server:
|
||||
description: Defines which server software to use for vhost. This role does nothing if set to none
|
||||
type: str
|
||||
required: false
|
||||
default: caddy
|
||||
choices:
|
||||
- caddy
|
||||
- none
|
||||
|
||||
proxy_target_port:
|
||||
description: Required and only applicable if vhost_type is reverse_proxy
|
||||
type: int
|
||||
proxy_target_host:
|
||||
description: Only applicable if vhost_type is reverse_proxy
|
||||
type: str
|
||||
default: localhost
|
||||
proxy_target_protocol:
|
||||
description: Only applicable if vhost_type is reverse_proxy
|
||||
type: str
|
||||
default: http
|
||||
|
||||
redirect_target:
|
||||
description: "Required and only applicable if vhost_type is redirect. Example: https://www.domain.tld/location"
|
||||
type: str
|
||||
redirect type:
|
||||
description: Only applicable if vhost_type is reverse_proxy
|
||||
type: str
|
||||
default: temporary
|
||||
choices:
|
||||
- temporary
|
||||
- permanent
|
||||
5
roles/vhost/meta/main.yml
Normal file
5
roles/vhost/meta/main.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
|
||||
dependencies:
|
||||
- role: caddy
|
||||
when: web_server == 'caddy'
|
||||
@@ -1,11 +1,12 @@
|
||||
---
|
||||
|
||||
- name: Add caddy reverse proxy config
|
||||
- name: Add caddy vhost config
|
||||
blockinfile:
|
||||
path: /etc/caddy/Caddyfile
|
||||
marker: "# {mark} ANSIBLE MANAGED BLOCK {{ vhost_id }}"
|
||||
block: |
|
||||
{{ vhost_domains | join(' ') }} {
|
||||
{% if vhost_type == 'reverse_proxy' %}
|
||||
reverse_proxy {{ proxy_target_protocol }}://{{ proxy_target_host }}:{{ proxy_target_port }} {
|
||||
{% if proxy_target_protocol == 'https' and proxy_target_host == 'localhost' %}
|
||||
transport http {
|
||||
@@ -13,8 +14,11 @@
|
||||
}
|
||||
{% endif %}
|
||||
}
|
||||
{% endif %}
|
||||
{% if vhost_type == 'redirect' %}
|
||||
redir {{ redirect_target }} {{ redirect_type }}
|
||||
{% endif %}
|
||||
}
|
||||
validate: 'caddy validate --config %s --adapter caddyfile'
|
||||
backup: true
|
||||
notify: reload caddy
|
||||
|
||||
6
roles/vhost/tasks/main.yml
Normal file
6
roles/vhost/tasks/main.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
|
||||
|
||||
- name: "Setup {{ vhost_id }} vhost on {{ web_server }}"
|
||||
include_tasks: "{{ web_server }}.yml"
|
||||
when: web_server != 'none'
|
||||
@@ -1,5 +1,8 @@
|
||||
---
|
||||
|
||||
reverse_proxy_type: caddy
|
||||
web_server: caddy
|
||||
|
||||
proxy_target_protocol: http
|
||||
proxy_target_host: localhost
|
||||
|
||||
redirect_type: temporary
|
||||
Reference in New Issue
Block a user