50 lines
1.1 KiB
YAML
50 lines
1.1 KiB
YAML
---
|
|
- name: Deploy Caddy
|
|
hosts: all
|
|
tasks:
|
|
- name: Create caddy user
|
|
user:
|
|
name: caddy
|
|
system: yes
|
|
shell: /usr/sbin/nologin
|
|
|
|
- name: Copy Caddy binary
|
|
copy:
|
|
src: caddy
|
|
dest: /usr/local/bin/caddy
|
|
mode: "0755"
|
|
|
|
- name: Check if systemd unit file exists
|
|
stat:
|
|
path: /etc/systemd/system/caddy.service
|
|
register: systemd_unit_file
|
|
|
|
- name: Create systemd unit file for Caddy
|
|
copy:
|
|
dest: /etc/systemd/system/caddy.service
|
|
content: |
|
|
[Unit]
|
|
Description=Caddy web server
|
|
After=network.target
|
|
|
|
[Service]
|
|
ExecStart=/usr/local/bin/caddy run --config /etc/caddy/Caddyfile
|
|
Restart=always
|
|
User=caddy
|
|
Group=caddy
|
|
EnvironmentFile=/etc/caddy/.env
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
when: not systemd_unit_file.stat.exists
|
|
|
|
- name: Enable and start Caddy service
|
|
systemd:
|
|
name: caddy
|
|
enabled: yes
|
|
state: started
|
|
|
|
- name: Restart Caddy service
|
|
systemd:
|
|
name: caddy
|
|
state: restarted
|