Skip to content

Caddy

Auto Documentation

Documentation Generated with Python on 2021-04-03

Default Variables

caddy_file_template: "CaddyFile.j2"

Tasks

main.yml

- include: folder.yml
- include: network.yml
- include: template.yml
- include: container.yml

network.yml

- name: create docker network
  docker_network:
    name: web

template.yml

# Deploy Docker net
- name: create caddy file
  template:
    src: "{{ caddy_file_template }}"
    dest: "{{ docker_dir }}/caddy/CaddyFile"
  notify:
    - restart caddy

folder.yml

# Deploy Docker Images
- name: ensures caddy directory dir exists
  file:
    path: "{{ item }}"
    state: directory
    owner: "{{ main_user}}"
    group: "{{ main_group }}"
  loop:
    - "{{ docker_dir }}"
    - "{{ docker_dir }}/caddy/data"
    - "{{ docker_dir }}/caddy/config"
    - "{{ docker_dir }}/caddy/certs"

container.yml

- name: caddy reverse proxy
  docker_container:
    name: caddy
    image: caddy:alpine
    restart_policy: always
    networks:
      - name: web
        aliases: caddy
    ports:
      - "80:80"
      - "443:443"
    mounts:
      - type: bind
        source: "{{ docker_dir }}/caddy/CaddyFile"
        target: /etc/caddy/Caddyfile
      - type: bind
        source: "{{ docker_dir }}/caddy/data"
        target: /data
      - type: bind
        source: "{{ docker_dir }}/caddy/config"
        target: /config
      - type: bind
        source: "{{ docker_dir }}/caddy/certs"
        target: /etc/caddycerts

Handlers

main.yml

- name: Restart Caddy
  docker_container:
    name: caddy
    restart: yes
  listen: restart caddy