-
Notifications
You must be signed in to change notification settings - Fork 0
/
caddy.yml
125 lines (111 loc) · 4.28 KB
/
caddy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# caddy.yml
# Authors:
# Andreas Räder, https://github.com/raederan
# Simon Stier, https://github.com/simontaurus
# Begin: Check Ansible User
- name: Check Ansible User
hosts: "{{ target_hosts | default('all') }}"
gather_facts: false
tasks:
- name: Fail reliably if 'ansible_user' is not defined
fail:
msg: "You need to set the right ansible_user in inventory.yml or by using the flag -u <USERNAME> when running the playbook!"
when: ansible_user is not defined
- name: Print 'ansible_user'
debug:
msg: "ansible_user: {{ ansible_user }}"
when: ansible_user is defined
# End: Check Ansible User
# Begin: Deploy Caddy
- name: Deploy Caddy
hosts: "{{ target_hosts | default('all') }}"
roles:
- kwoodson.yedit
tasks:
- name: Verify SSH connection
ansible.builtin.wait_for_connection:
- name: Clone caddy repository
ansible.builtin.git:
repo: https://github.com/OpenSemanticWorld/caddy-docker-proxy
dest: /usr/local/docker-container/caddy-docker-proxy
version: "main"
# force: yes
- name: Ensure folder exists and permissions are set
ansible.builtin.file:
path: /usr/local/docker-container/caddy-docker-proxy
owner: "{{ ansible_user }}"
state: directory
mode: 0755
- name: Copy .env.example to .env
ansible.builtin.copy:
src: /usr/local/docker-container/caddy-docker-proxy/.env.example
dest: /usr/local/docker-container/caddy-docker-proxy/.env
remote_src: yes
owner: "{{ ansible_user }}"
mode: 0644
force: no
when: acme_ca is defined and acme_eab_key_id is defined and acme_eab_mac_key is defined
- name: Create/Replace values by key dict in .env file
lineinfile:
path: /usr/local/docker-container/caddy-docker-proxy/.env
regexp: "^{{ item.key }}=.*$"
line: "{{ item.key }}={{ item.value }}"
backrefs: no # yes enables capture groups
# dict refers to new untracked .env copied from .env.example
# https://github.com/OpenSemanticLab/docker-compose-osl-wiki/blob/main/.example.env
# add or change valid key-value pairs to your needs and set vars in inventory.yml
with_dict:
ACME_CA: "{{ acme_ca }}"
ACME_EAB_KEY_ID: "{{ acme_eab_key_id }}"
ACME_EAB_MAC_KEY: "{{ acme_eab_mac_key }}"
when: acme_ca is defined and acme_eab_key_id is defined and acme_eab_mac_key is defined
- name: Copy Compose Override Caddy
ansible.builtin.copy:
src: /usr/local/docker-container/caddy-docker-proxy/docker-compose.custom.override.yml
dest: /usr/local/docker-container/caddy-docker-proxy/docker-compose.override.yml
remote_src: yes
owner: "{{ ansible_user }}"
mode: 0644
force: yes
when: acme_ca is defined and acme_eab_key_id is defined and acme_eab_mac_key is defined
- name: Create a network
docker_network:
name: caddy
# - name: Manage docker-compose.yml of caddy-docker-proxy
# when: false # we use the default docker-compose.yml for now
# yedit:
# src: /usr/local/docker-container/caddy-docker-proxy/docker-compose.yml
# value:
# version: "3.7"
# services:
# caddy:
# image: lucaslorentz/caddy-docker-proxy:ci-alpine
# container_name: caddycontainer
# ports:
# - 80:80
# - 443:443
# environment:
# - CADDY_INGRESS_NETWORKS=caddy
# networks:
# - caddy
# volumes:
# - /var/run/docker.sock:/var/run/docker.sock
# - caddy_data:/data
# restart: unless-stopped
# networks:
# caddy:
# external: true
# volumes:
# caddy_data: {}
- name: Create and start caddy service
community.docker.docker_compose:
project_src: /usr/local/docker-container/caddy-docker-proxy
register: caddyproxy
# - name: Print register variable for debugging
# debug:
# var: caddyproxy
- name: Verify if caddy is running
ansible.builtin.assert:
that:
- "caddyproxy.services.caddy.caddycontainer.state.running"
# End: Deploy Caddy