ansible: 添加 xray 服务部署配置

This commit is contained in:
2026-08-23 01:05:08 +08:00
parent 3329694df2
commit 0f79d5ca9b
3 changed files with 83 additions and 29 deletions

View File

@@ -0,0 +1,45 @@
---
- name: 配置 xray 服务
hosts: vps_debian
become: true
gather_facts: false
vars:
xray_config_file: /usr/local/etc/xray/config.json
xray_bin: /usr/local/bin/xray
vars_files:
- ../vars/vault.yaml
tasks:
- name: 确保有 curl 软件包
apt:
name:
- curl
state: present
update_cache: true
- name: 安装 xray
shell: |
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
notify: restart xray
- name: 生成 xray 配置
template:
src: ../templates/xray-config.json.j2
dest: "{{ xray_config_file }}"
owner: root
group: root
mode: '0644'
notify: restart xray
- name: 启动 xray 服务并添加开机启动
systemd:
name: xray
enabled: true
state: started
daemon_reload: true
handlers:
- name: restart xray
systemd:
name: xray
state: restarted