Skip to content

Commit

Permalink
feat: update modules + add metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
angristan committed Nov 13, 2022
1 parent 5104f07 commit d25b556
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 38 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Use this config to use the Cloudflare API for the DNS-01 ACME challenge:
cloudflare_token: xxx
caddy_tls_dns_cloudflare_enabled: true
caddy_env_vars:
- 'CLOUDFLARE_API_TOKEN={{ cloudflare_token }}'
- "CLOUDFLARE_API_TOKEN={{ cloudflare_token }}"
```
Otherwise, Caddy will default to HTTP-01 or TLS-ALPN-01.
Expand All @@ -46,11 +46,11 @@ caddy_vhosts:
proxy_host: http://10.0.0.1
gzip: compress
security_headers: true
responds: ['/forbidden 403']
rewrites: ['* /path{uri}']
responds: ["/forbidden 403"]
rewrites: ["* /path{uri}"]
- name: site2
hostname: site1.domain.tld
template: custom_template.j2
ansible.builtin.template: custom_template.j2
```

By default, the vhosts will use the `reverse.j2` template included in the role. Look at it and the `defaults/main.yml` file for all variables!
Expand All @@ -66,8 +66,8 @@ By default, the vhosts will use the `reverse.j2` template included in the role.
- { role: angristan.caddy, tags: caddy }
vars:
caddy_vhosts:
- name: 'website'
hostname: 'website.tld'
- name: "website"
hostname: "website.tld"
```

## Usage
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export GOOS=linux
export GOARCH=amd64

# go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
xcaddy build --with github.com/caddy-dns/cloudflare --output bin/caddy
# xcaddy build --with github.com/caddy-dns/cloudflare --with github.com/lindenlab/caddy-s3-proxy --output bin/caddy
# xcaddy build --with github.com/caddy-dns/cloudflare --with github.com/greenpau/caddy-auth-jwt --with github.com/greenpau/caddy-auth-portal --output bin/caddy-auth
3 changes: 2 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ caddy_user_id: 333
caddy_group_id: 33
caddy_env_vars: []
caddy_service_after_units: []
caddy_metrics_enabled: true

# TLS
caddy_tls_dns_cloudflare_enabled: false
Expand All @@ -24,7 +25,7 @@ caddy_vhost_defaults:
proxy_transparent_disable: false
security_headers: false
basicauth: false
basicauth_path: '/'
basicauth_path: "/"
www_redir: false
root: null
php_fastcgi_enabled: null
Expand Down
1 change: 0 additions & 1 deletion files/Caddyfile

This file was deleted.

54 changes: 27 additions & 27 deletions tasks/setup.yml
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
---
- name: Upload caddy binary
copy:
src: '{{ caddy_src_bin }}'
dest: '{{ caddy_bin_path }}'
mode: '0755'
ansible.builtin.copy:
src: "{{ caddy_src_bin }}"
dest: "{{ caddy_bin_path }}"
mode: "0755"
notify: caddy restart

- name: Add caddy group
group:
name: '{{ caddy_group_name }}'
gid: '{{ caddy_group_id }}'
ansible.builtin.group:
name: "{{ caddy_group_name }}"
gid: "{{ caddy_group_id }}"

- name: Add caddy user
user:
name: '{{ caddy_user_name }}'
uid: '{{ caddy_user_id }}'
group: '{{ caddy_group_id }}'
home: '{{ caddy_user_home_dir }}'
ansible.builtin.user:
name: "{{ caddy_user_name }}"
uid: "{{ caddy_user_id }}"
group: "{{ caddy_group_id }}"
home: "{{ caddy_user_home_dir }}"
create_home: true
shell: '/usr/sbin/nologin'
shell: "/usr/sbin/nologin"
system: true

- name: Create Caddy systemd unit file
template:
ansible.builtin.template:
src: caddy.service.j2
dest: /etc/systemd/system/caddy.service
mode: 0644
notify: service modified

- name: Create config directory
file:
path: '{{ caddy_config_path }}'
ansible.builtin.file:
path: "{{ caddy_config_path }}"
state: directory
mode: 0755

- name: Create snippets directory
file:
path: '{{ caddy_config_path }}/snippets'
ansible.builtin.file:
path: "{{ caddy_config_path }}/snippets"
state: directory
mode: 0755

- name: Create vhosts directory
file:
path: '{{ caddy_config_path }}/vhosts'
ansible.builtin.file:
path: "{{ caddy_config_path }}/vhosts"
state: directory
mode: 0755

- name: Create log directory
file:
path: '{{ caddy_log_path }}'
ansible.builtin.file:
path: "{{ caddy_log_path }}"
state: directory
mode: 0755
owner: caddy

- name: Add Caddyfile
copy:
src: Caddyfile
dest: '{{ caddy_config_path }}/Caddyfile'
ansible.builtin.template:
src: Caddyfile.j2
dest: "{{ caddy_config_path }}/Caddyfile"
mode: 0644
notify: caddy reload

- name: Copy TLS config snippet
template:
ansible.builtin.template:
mode: 0644
src: tls.conf.j2
dest: '{{ caddy_config_path }}/snippets/tls.conf'
dest: "{{ caddy_config_path }}/snippets/tls.conf"
notify: caddy reload

- name: Enable and start Caddy service
Expand Down
6 changes: 3 additions & 3 deletions tasks/vhosts.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
- name: Add vhost
template:
src: '{{ vhost.template }}'
dest: '{{ caddy_config_path }}/vhosts/{{ vhost.name }}'
ansible.builtin.template:
src: "{{ vhost.template }}"
dest: "{{ caddy_config_path }}/vhosts/{{ vhost.name }}"
mode: 0644
notify: caddy reload
tags: caddy.vhosts
9 changes: 9 additions & 0 deletions templates/Caddyfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% if caddy_metrics_enabled %}
{
servers {
metrics
}
}
{% endif %}

import vhosts/*

0 comments on commit d25b556

Please sign in to comment.