Initial commit

This commit is contained in:
YuanHui
2025-07-11 15:48:18 +08:00
commit 1d7f6cc8fc
12 changed files with 743 additions and 0 deletions

47
deploy_caddy.yml Normal file
View File

@@ -0,0 +1,47 @@
---
- name: Deploy and Reload Caddy & frpc on Heterogeneous Systems
hosts: caddy_servers
become: yes
# # 'pre_tasks' 会在所有常规 'tasks' 之前执行
# pre_tasks:
# - name: "(Alpine Only) Ensure Python 3 is installed for Ansible"
# # 使用 'raw' 模块,因为它不依赖 Python
# # 这是一个标准的在 Alpine 上引导 Ansible 的方法
# raw: test -e /usr/bin/python3 || (apk update && apk add python3)
# register: result
# changed_when: "'OK' in result.stdout or 'fetch' in result.stdout"
# # 'when' 条件确保这个任务只在 Alpine 系统上运行
# when: ansible_os_family == "Alpine"
tasks:
# --- Caddy 任务 (保持不变) ---
- name: "Copy Caddyfile for {{ inventory_hostname }}"
copy:
src: "files/{{ inventory_hostname }}/Caddyfile"
dest: /etc/caddy/Caddyfile
owner: root
group: caddy
mode: '0644'
validate: 'caddy validate --config %s --adapter caddyfile'
notify: Reload Caddy
handlers:
# --- Caddy Handlers (保持不变) ---
- name: Reload Caddy on systemd systems (e.g., Ubuntu)
# Both handlers listen for the same notification
listen: "Reload Caddy"
systemd:
name: caddy
state: reloaded
# This handler ONLY runs on systems with systemd
when: ansible_service_mgr == "systemd"
- name: Reload Caddy on OpenRC systems (e.g., Alpine)
# Both handlers listen for the same notification
listen: "Reload Caddy"
# For Alpine, we use the 'command' module to call its service manager
command: rc-service caddy reload
# This handler ONLY runs on systems with openrc
when: ansible_service_mgr == "openrc"