Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: refactor: use caddy over api #77

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 40 additions & 15 deletions group_vars/web/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,44 @@ port_mapping:
alertmanager: 9093
node: 9100

# TODO(paulfantom): reenable when https://github.com/caddy-ansible/caddy-ansible/issues/13 is fixed
caddy_update: false
# # TODO(paulfantom): reenable when https://github.com/caddy-ansible/caddy-ansible/issues/13 is fixed
# caddy_update: false
#
# caddy_systemd_capabilities_enabled: true
# caddy_systemd_restart_startlimitinterval: 3600
# caddy_config: |
# {{ ansible_host }} {
# try_files {path}.html {path}
# root * /var/www/demo/
# file_server
# }
# {# for name, port in port_mapping.items() %}
# {{ name }}.{{ ansible_host }} {
# reverse_proxy 127.0.0.1:{{ port }}
# }
# {% endfor #}

caddy_systemd_capabilities_enabled: true
caddy_systemd_restart_startlimitinterval: 3600
caddy_config: |
{{ ansible_host }} {
try_files {path}.html {path}
root * /var/www/demo/
file_server
}
{% for name, port in port_mapping.items() %}
{{ name }}.{{ ansible_host }} {
reverse_proxy 127.0.0.1:{{ port }}
}
{% endfor %}
caddy_json_config:
apps:
http:
servers:
demo:
listen:
- ":80"
- ":443"
routes:
- match:
- host:
- "{{ ansible_host }}"
handle:
- handler: "static_response"
body: "{{ lookup('ansible.builtin.file', 'index.html') }}"
{% for name, port in port_mapping.items() %}
- match:
- host:
- "{{ name }}.{{ ansible_host }}"
handle:
- handler: "reverse_proxy"
upstreams:
- dial: "127.0.0.1:{{ port }}"
{% endfor %}
40 changes: 20 additions & 20 deletions playbooks/01_webserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
- name: Setup HTTP server
hosts: web
roles:
- caddy_ansible.caddy_ansible
pre_tasks:
- name: Ensure webdirs exists
ansible.builtin.file:
mode: '0755'
path: "{{ item }}"
state: directory
loop:
- /var/www/demo
- /var/www/demo/img
- name: Ensure portal site exists
ansible.builtin.copy:
mode: '0644'
src: index.html
dest: /var/www/demo/index.html
- name: Copy digitalocean image
ansible.builtin.get_url:
url: "https://github.com/prometheus/demo-site/raw/prometheus/playbooks/files/img/digitalocean.png"
dest: "/var/www/demo/img/digitalocean.png"
mode: 0644
- maxhoesel.caddy.caddy_server
# pre_tasks:
# - name: Ensure webdirs exists
# ansible.builtin.file:
# mode: '0755'
# path: "{{ item }}"
# state: directory
# loop:
# - /var/www/demo
# - /var/www/demo/img
# - name: Ensure portal site exists
# ansible.builtin.copy:
# mode: '0644'
# src: index.html
# dest: /var/www/demo/index.html
# - name: Copy digitalocean image
# ansible.builtin.get_url:
# url: "https://github.com/prometheus/demo-site/raw/prometheus/playbooks/files/img/digitalocean.png"
# dest: "/var/www/demo/img/digitalocean.png"
# mode: 0644
4 changes: 2 additions & 2 deletions roles/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ collections:
type: galaxy
- name: devsec.hardening
type: galaxy
- name: maxhoesel.caddy

roles:
- name: cloudalchemy.grafana

# EXTRAS
- name: caddy_ansible.caddy_ansible
- name: hifis.unattended_upgrades
version: "v3.2.0"
version: "v3.2.0"