{"id":22620548,"url":"https://github.com/dbrennand/ansible-role-caddy-docker","last_synced_at":"2025-10-03T18:13:30.047Z","repository":{"id":116025453,"uuid":"541155986","full_name":"dbrennand/ansible-role-caddy-docker","owner":"dbrennand","description":"Ansible role to deploy Caddy in a Docker container.","archived":false,"fork":false,"pushed_at":"2024-02-18T18:30:34.000Z","size":45,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T22:39:03.798Z","etag":null,"topics":["ansible","ansible-role","caddy","caddy-docker","caddyserver","docker"],"latest_commit_sha":null,"homepage":"https://galaxy.ansible.com/dbrennand/caddy_docker","language":"Jinja","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dbrennand.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-09-25T11:58:11.000Z","updated_at":"2024-10-21T01:54:37.000Z","dependencies_parsed_at":"2024-01-13T12:26:10.135Z","dependency_job_id":"78eac7df-09c6-459f-981c-60d690856bd0","html_url":"https://github.com/dbrennand/ansible-role-caddy-docker","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbrennand%2Fansible-role-caddy-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbrennand%2Fansible-role-caddy-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbrennand%2Fansible-role-caddy-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbrennand%2Fansible-role-caddy-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dbrennand","download_url":"https://codeload.github.com/dbrennand/ansible-role-caddy-docker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248432038,"owners_count":21102305,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-role","caddy","caddy-docker","caddyserver","docker"],"created_at":"2024-12-08T22:14:17.926Z","updated_at":"2025-10-03T18:13:30.041Z","avatar_url":"https://github.com/dbrennand.png","language":"Jinja","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ansible Role: dbrennand.caddy_docker\n\n![Ansible-Lint](https://github.com/dbrennand/ansible-role-caddy-docker/actions/workflows/ansible-lint.yml/badge.svg)\n![Molecule](https://github.com/dbrennand/ansible-role-caddy-docker/actions/workflows/molecule.yml/badge.svg)\n![Ansible-Release](https://github.com/dbrennand/ansible-role-caddy-docker/actions/workflows/ansible-release.yml/badge.svg)\n\nAnsible role to deploy [Caddy](https://caddyserver.com/) in a Docker container.\n\n## Requirements\n\n* [Docker](https://www.docker.com/)\n\n* [Docker SDK for Python](https://docker-py.readthedocs.io/en/stable/)\n\n* [`community.docker`](https://galaxy.ansible.com/community/docker) Ansible collection:\n\n  ```bash\n  ansible-galaxy collection install community.docker\n  ```\n\n## Role Variables\n\n```yaml\ncaddy_docker_state: present\n```\n\nManage the state of the resources deployed by this role. Set to `absent` to remove the Caddy directories (data and config), Caddyfile, Docker network(s), image and container.\n\n```yaml\ncaddy_docker_config_directory:\n  path: ~/.config/caddy\n  # Optional\n  # owner: owner\n  # group: group\n  # mode: 0755\ncaddy_docker_data_directory:\n  path: ~/.local/share/caddy\n  # ...\ncaddy_docker_caddyfile_directory:\n  path: ~/.config/caddyfile\n  # ...\n```\n\nAbsolute path to the Caddy config directory, data directory and directory to place the Caddyfile into. Attached to the container as bind mounts.\n\n```yaml\ncaddy_docker_caddyfile: |-\n  localhost\n  respond \"Hello, world!\"\n```\n\nContents of the [Caddyfile](https://caddyserver.com/docs/caddyfile) used to configure Caddy.\n\n```yaml\ncaddy_docker_caddyfile_file:\n  path: \"{{ caddy_docker_caddyfile_directory.path }}/Caddyfile\"\n  # ...\n```\n\nAbsolute path to the Caddyfile to be created. You should not need to modify this variable in most scenarios and leave it as the default.\n\n```yaml\ncaddy_docker_image: caddy:2.10.0-alpine\ncaddy_docker_builder_image: caddy:2.10.0-builder\n```\n\nContainer image repositories, names and tags used to deploy Caddy as a container. The `caddy_docker_builder_image` variable is only used when `caddy_docker_plugins` is populated.\n\n```yaml\ncaddy_docker_builder_directory:\n  path: /tmp/caddy-builder/\n  # ...\n```\n\nAbsolute path for the directory used as the container build context. This variable is only used when `caddy_docker_plugins` is populated. You may want to override this variable if you bring your own dockerfile template and want to include files during the Caddy container's build process.\n\n```yaml\ncaddy_docker_builder_template: dockerfile.j2\n# Using the lookup plugin\n# caddy_docker_builder_template: \"{{ lookup('template', 'templates/dockerfile.custom.j2') }}\"\n```\n\nDockerfile template used to build the Caddy container. This variable is only used when `caddy_docker_plugins` is populated.\n\n```yaml\ncaddy_docker_builder_force: false\n```\n\nWhether or not to force a rebuild of the Caddy container. This variable is only used when `caddy_docker_plugins` is populated.\n\n```yaml\ncaddy_docker_plugins: []\n# Example\n# caddy_docker_plugins:\n#   - github.com/caddy-dns/cloudflare\n#   - github.com/lucaslorentz/caddy-docker-proxy/v2\n```\n\nList of plugins to include in the Caddy container.\n\n```yaml\ncaddy_docker_networks:\n  - name: caddy\n```\n\nNames of the Docker networks to be created and attached to the Caddy container.\n\n```yaml\ncaddy_docker_network_mode: default\n```\n\nDocker network mode to use for the Caddy container. The `caddy_docker_networks`, `caddy_docker_ports` and `caddy_docker_exposed_ports` variables have no affect when this variable is set to `host`.\n\n```yaml\ncaddy_docker_command: caddy run --config /etc/caddy/Caddyfile --adapter caddyfile\n```\n\nCommand for starting the Caddy container. You may want to override this when using plugins.\n\n```yaml\ncaddy_docker_restart_policy: unless-stopped\n```\n\nRestart policy for the Caddy container.\n\n```yaml\ncaddy_docker_ports:\n  - 80:80\n  - 443:443\n  - \"443:443/udp\"\ncaddy_docker_exposed_ports: []\n# Example\n# caddy_docker_exposed_ports:\n#   - 9000\n```\n\nPorts to expose on the Caddy container.\n\n```yaml\ncaddy_docker_etc_hosts: {}\n# Example\n# caddy_docker_etc_hosts:\n#   host.docker.internal: host-gateway\n```\n\nHost to IP mappings to place into the Caddy container's `/etc/hosts` file.\n\n```yaml\ncaddy_docker_extra_volumes: []\n# Example\n# caddy_docker_extra_volumes:\n#   - /site:/srv\n```\n\nExtra volumes to attach to the Caddy container.\n\n```yaml\ncaddy_docker_environment_variables: {}\n# Example\n# caddy_docker_environment_variables:\n#   DOMAIN: example.com\n```\n\nEnvironment variables to apply to the Caddy container.\n\n## Dependencies\n\nNone.\n\n## Example Playbook\n\n```yaml\n- name: dbrennand.caddy_docker\n  hosts: all\n  vars:\n    pip_install_packages:\n      - name: docker\n  pre_tasks:\n    - name: Update apt cache\n      ansible.builtin.apt:\n        update_cache: true\n  roles:\n    - geerlingguy.pip\n    - geerlingguy.docker\n    - dbrennand.caddy_docker\n```\n\n### Example - Cloudflare DNS-01 Challenge\n\nThis example uses the [Cloudflare module for Caddy](https://github.com/caddy-dns/cloudflare) to obtain certificates (including wildcards) from Let's Encrypt for a [Cloudflare](https://www.cloudflare.com) managed domain. This is useful when you want to obtain certificates without opening port 80 (HTTP) to the internet.\n\nYou **must** generate an API token for Caddy to authenticate to the Cloudflare API and create a TXT record for the DNS-01 challenge:\n\n1. Go to the [Cloudflare dashboard profile page](https://dash.cloudflare.com/profile).\n\n2. On the left select **API Tokens** \u003e **Create Token**.\n\n3. Select the API token template named **Edit zone DNS**.\n\n4. Modify the **Token name** to your liking.\n\n5. Under *Permissions* select **+ Add more** and add the permission: `Zone / Zone / Read`.\n\n6. Under *Zone Resources* include your zone: `Include / Specific zone / example.tld`.\n\n7. *Optional* - Configure Client IP Address Filtering if desired.\n\n8. Click **Continue to summary** \u003e **Create Token**.\n\n```yaml\n- name: dbrennand.caddy_docker - Cloudflare\n  hosts: all\n  vars:\n    # geerlingguy.pip role vars\n    pip_install_packages:\n      - name: docker\n    # dbrennand.caddy_docker role vars\n    caddy_docker_caddyfile: |-\n      {\n              email {$ACME_EMAIL}\n      }\n\n      # Cloudflare DNS-01 challenge\n      (cloudflare) {\n              tls {\n                      dns cloudflare {$CLOUDFLARE_API_TOKEN}\n              }\n      }\n\n      service.{$DOMAIN} {\n              import cloudflare\n              reverse_proxy container:port\n      }\n    caddy_docker_plugins:\n      - github.com/caddy-dns/cloudflare\n    caddy_docker_environment_variables:\n      DOMAIN: domain.tld\n      ACME_EMAIL: email@domain.tld\n      CLOUDFLARE_API_TOKEN: token\n  pre_tasks:\n    - name: Update apt cache\n      ansible.builtin.apt:\n        update_cache: true\n  roles:\n    - geerlingguy.pip\n    - geerlingguy.docker\n    - dbrennand.caddy_docker\n```\n\n### Example - [Tailscale](https://tailscale.com/)\n\nThis example uses [artis3n/ansible-role-tailscale](https://github.com/artis3n/ansible-role-tailscale) to install Tailscale and configure Caddy to obtain a certificate from Let's Encrypt for your Tailscale node. You **must** have [MagicDNS](https://tailscale.com/kb/1081/magicdns/) and [HTTPS Certificate](https://tailscale.com/kb/1153/enabling-https/) features enabled for your Tailnet.\n\n```yaml\n- name: dbrennand.caddy_docker - Tailscale\n  hosts: all\n  vars:\n    # geerlingguy.pip role vars\n    pip_install_packages:\n      - name: docker\n    # artis3n.tailscale role vars\n    tailscale_authkey: key\n    # dbrennand.caddy_docker role vars\n    caddy_docker_caddyfile: |-\n      {\n              email {$ACME_EMAIL}\n      }\n\n      # Tailscale\n      (tailscale) {\n              tls {\n                      get_certificate tailscale\n              }\n      }\n\n      node.{$TAILNET} {\n              import tailscale\n              reverse_proxy container:port\n      }\n    caddy_docker_extra_volumes:\n      - /var/run/tailscale/tailscaled.sock:/var/run/tailscale/tailscaled.sock\n    caddy_docker_environment_variables:\n      ACME_EMAIL: email@domain.tld\n      TAILNET: domain-alias.ts.net\n  pre_tasks:\n    - name: Update apt cache\n      ansible.builtin.apt:\n        update_cache: true\n  roles:\n    - geerlingguy.pip\n    - geerlingguy.docker\n    - artis3n.tailscale\n    - dbrennand.caddy_docker\n```\n\n## Molecule Tests 🧪\n\nTo test the role, use molecule: `molecule test`\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) for details.\n\n## Authors \u0026 Contributors\n\n[**dbrennand**](https://github.com/dbrennand) - *Author*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdbrennand%2Fansible-role-caddy-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdbrennand%2Fansible-role-caddy-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdbrennand%2Fansible-role-caddy-docker/lists"}