Add basic caddy swarm role
Added caddy as swarm container. Uses templated Caddyfile which can be set up for testing purposes for now. Depends on docker and docker-swarm, and will keep its stuff where docker-swarm sets itself up.
This commit is contained in:
parent
453cd2fd2b
commit
9f188c2674
7 changed files with 102 additions and 0 deletions
13
roles/caddy/defaults/main.yml
Normal file
13
roles/caddy/defaults/main.yml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
|
||||
caddy_version: alpine
|
||||
caddy_caddyfile_dir: "{{ docker_stack_files_dir }}/caddy"
|
||||
|
||||
caddy_use_debug: no
|
||||
|
||||
caddy_use_https: yes
|
||||
caddy_tls_use_staging: no
|
||||
# caddy_email: your@email.here
|
||||
|
||||
# sets up a quick test server on port 80 to see if the container is set up correctly
|
||||
caddy_create_test_file_server: no
|
||||
5
roles/caddy/meta/main.yml
Normal file
5
roles/caddy/meta/main.yml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
|
||||
dependencies:
|
||||
- docker
|
||||
- docker-swarm
|
||||
27
roles/caddy/tasks/main.yml
Normal file
27
roles/caddy/tasks/main.yml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
# install caddy as a docker stack
|
||||
|
||||
- name: Ensure Caddyfile directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ caddy_caddyfile_dir }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
become: true
|
||||
|
||||
- name: Ensure Caddyfile exists
|
||||
ansible.builtin.template:
|
||||
src: Caddyfile.j2
|
||||
dest: "{{ caddy_caddyfile_dir }}/Caddyfile"
|
||||
validate: "docker run --rm -v %s:/Caddyfile caddy caddy validate --config /Caddyfile"
|
||||
become: true
|
||||
|
||||
- name: Deploy caddy to swarm
|
||||
community.general.docker_stack:
|
||||
name: "{{ item.name }}"
|
||||
state: present
|
||||
prune: yes
|
||||
compose:
|
||||
- "{{ item.compose }}"
|
||||
with_items: "{{ caddy_stack }}"
|
||||
when: caddy_stack is defined
|
||||
become: yes
|
||||
26
roles/caddy/templates/Caddyfile.j2
Normal file
26
roles/caddy/templates/Caddyfile.j2
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
{%- if caddy_email is not none %}
|
||||
email {{ caddy_email }}
|
||||
{% endif %}
|
||||
|
||||
{% if caddy_tls_use_staging is sameas true %}
|
||||
acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
|
||||
{% endif %}
|
||||
|
||||
{% if caddy_use_debug is sameas true %}
|
||||
debug
|
||||
{% endif %}
|
||||
|
||||
{% if caddy_use_https is sameas false %}
|
||||
auto_https off
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
{% if caddy_create_test_file_server is sameas true %}
|
||||
:80 {
|
||||
file_server {
|
||||
browse
|
||||
}
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
22
roles/caddy/templates/docker-stack.yml.j2
Normal file
22
roles/caddy/templates/docker-stack.yml.j2
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
version: "3.7"
|
||||
|
||||
services:
|
||||
app:
|
||||
image: caddy:{{ caddy_version }}
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- "{{ caddy_caddyfile_dir }}:/etc/caddy"
|
||||
- data:/data
|
||||
- config:/config
|
||||
networks:
|
||||
- "{{ docker_swarm_public_network_name }}"
|
||||
|
||||
volumes:
|
||||
data:
|
||||
config:
|
||||
|
||||
networks:
|
||||
"{{ docker_swarm_public_network_name }}":
|
||||
external: true
|
||||
5
roles/caddy/vars/main.yml
Normal file
5
roles/caddy/vars/main.yml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
|
||||
caddy_stack:
|
||||
- name: caddy
|
||||
compose: "{{ lookup('template', 'docker-stack.yml.j2') | from_yaml }}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue