This guide provides a full Ansible playbook to install Caddy with distro-aware package handling and baseline service configuration for Debian 10+, Ubuntu LTS, and RHEL 9+ compatible systems.
- name: Install Caddy
hosts: caddy
become: true
vars:
app_config_dir: /etc/caddy
tasks:
- name: Install package on Debian/Ubuntu
apt:
name:
- caddy
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install package on RHEL family
dnf:
name:
- caddy
state: present
when: ansible_os_family == "RedHat"
- name: Create configuration directory
file:
path: "{{ app_config_dir }}"
state: directory
mode: "0755"
- name: Enable and start service
service:
name: caddy
state: started
enabled: true
failed_when: false
- name: Verify binary is available
command: "caddy --version"
register: app_version
changed_when: false
failed_when: false
- name: Show detected version output
debug:
var: app_version.stdout
Beyond this playbook, we offer:
Contact our automation team: office@linux-server-admin.com