Implement a role for deploying Caddy

This commit is contained in:
Alexander Gorelyshev
2026-05-15 14:48:20 +04:00
parent 970c6d3266
commit e5db5ab20b
11 changed files with 262 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
---
- name: Converge
hosts: all
roles:
- role: genlab.common.caddy
caddy_src_conf_path: "files/Caddyfile"
caddy_dest_conf_path: "/etc/caddy/Caddyfile"
caddy_version: "2.11.3"
caddy_limit_nofile: 1048576

View File

@@ -0,0 +1,3 @@
:8080 {
respond "caddy-ok" 200
}

View File

@@ -0,0 +1,24 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: ubuntu
image: geerlingguy/docker-ubuntu2404-ansible:latest
pre_build_image: true
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
provisioner:
name: ansible
playbooks:
converge: converge.yml
verifier:
name: ansible
lint: |
set -e
yamllint .
ansible-lint .

View File

@@ -0,0 +1,34 @@
---
- name: Verify
hosts: all
gather_facts: false
pre_tasks:
# https://github.com/ansible/molecule/issues/3587#issuecomment-1158650179
- name: "Include default vars"
ansible.builtin.include_vars:
dir: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/defaults/"
extensions: ['yml']
tasks:
- name: "Wait for Caddy to start and listen on the configured port"
ansible.builtin.wait_for:
port: 8080
delay: 2
timeout: 10
# kics-scan ignore-block - kics doesn't like HTTP but on localhost it's not important
- name: "Get the Caddy daemon response"
retries: 3
delay: 1
register: caddy_response
ansible.builtin.uri:
url: "http://localhost:8080"
return_content: true
- name: "Assert Caddy is responding corectly"
ansible.builtin.assert:
that:
- caddy_response.status == 200
- "caddy_response.content == 'caddy-ok'"
success_msg: "OK: HTTP {{ caddy_response.status }}, '{{ caddy_response.content }}'"
fail_msg: "FAIL: HTTP {{ caddy_response.status }}, '{{ caddy_response.content }}'"