147 lines
4.1 KiB
YAML
147 lines
4.1 KiB
YAML
---
|
|||
|
|
- name: create xray-lists group
|
||
|
|
ansible.builtin.group:
|
||
|
|
name: xray-lists
|
||
|
|
system: true
|
||
|
|
state: present
|
||
|
|
|
||
|
|
- name: create xray-lists user
|
||
|
|
ansible.builtin.user:
|
||
|
|
name: xray-lists
|
||
|
|
group: xray-lists
|
||
|
|
system: true
|
||
|
|
shell: /usr/sbin/nologin
|
||
|
|
home: /var/lib/xray-lists
|
||
|
|
create_home: true
|
||
|
|
state: present
|
||
|
|
|
||
|
|
- name: install required system packages
|
||
|
|
ansible.builtin.apt:
|
||
|
|
name:
|
||
|
|
- python3-venv
|
||
|
|
- git
|
||
|
|
- rsync
|
||
|
|
state: present
|
||
|
|
update_cache: true
|
||
|
|
|
||
|
|
- name: ensure xray-lists directory exists
|
||
|
|
ansible.builtin.file:
|
||
|
|
path: "/etc/xray-lists"
|
||
|
|
state: directory
|
||
|
|
owner: "root"
|
||
|
|
group: "root"
|
||
|
|
mode: "0755"
|
||
|
|
|
||
|
|
- name: ensure local mirror of xray-lists exists on the runner
|
||
|
|
ansible.builtin.git:
|
||
|
|
repo: "https://gitea.oyacoi.ru/pyrschtjag/xray-lists.git"
|
||
|
|
dest: "{{ xray_lists_runner_mirror | default(lookup('env','HOME') + '/.cache/xray-lists-mirror') }}"
|
||
|
|
version: main
|
||
|
|
force: true
|
||
|
|
delegate_to: localhost
|
||
|
|
run_once: true
|
||
|
|
ignore_errors: true
|
||
|
|
vars:
|
||
|
|
ansible_connection: local
|
||
|
|
|
||
|
|
- name: attempt to clone/update xray-lists repository directly on the host
|
||
|
|
block:
|
||
|
|
- name: clone xray-lists repository from gitea on the host
|
||
|
|
ansible.builtin.git:
|
||
|
|
repo: "https://gitea.oyacoi.ru/pyrschtjag/xray-lists.git"
|
||
|
|
dest: /opt/xray-lists/xray-lists-src
|
||
|
|
version: main
|
||
|
|
force: true
|
||
|
|
rescue:
|
||
|
|
- name: warn that gitea is unreachable from the host
|
||
|
|
ansible.builtin.debug:
|
||
|
|
msg: "gitea.oyacoi.ru is unreachable from this host, falling back to the local copy from the runner"
|
||
|
|
|
||
|
|
- name: check whether the runner has a usable local mirror
|
||
|
|
ansible.builtin.stat:
|
||
|
|
path: "{{ xray_lists_runner_mirror | default(lookup('env','HOME') + '/.cache/xray-lists-mirror') }}/.git"
|
||
|
|
register: runner_mirror_stat
|
||
|
|
delegate_to: localhost
|
||
|
|
vars:
|
||
|
|
ansible_connection: local
|
||
|
|
|
||
|
|
- name: abort if the runner has no local mirror either
|
||
|
|
ansible.builtin.fail:
|
||
|
|
msg: "gitea is unreachable and the runner has no local mirror of xray-lists - cannot deploy"
|
||
|
|
when: not runner_mirror_stat.stat.exists
|
||
|
|
|
||
|
|
- name: ensure xray-lists-src directory exists on the host before sync
|
||
|
|
ansible.builtin.file:
|
||
|
|
path: /opt/xray-lists/xray-lists-src
|
||
|
|
state: directory
|
||
|
|
owner: root
|
||
|
|
group: root
|
||
|
|
mode: "0755"
|
||
|
|
|
||
|
|
- name: sync xray-lists source (including .git) from the runner to the host
|
||
|
|
ansible.posix.synchronize:
|
||
|
|
src: "{{ xray_lists_runner_mirror | default(lookup('env','HOME') + '/.cache/xray-lists-mirror') }}/"
|
||
|
|
dest: "root@{{ ip }}:/opt/xray-lists/xray-lists-src/"
|
||
|
|
rsync_opts:
|
||
|
|
- "--delete"
|
||
|
|
|
||
|
|
- name: create python venv for xray-lists
|
||
|
|
ansible.builtin.command: python3 -m venv /opt/xray-lists/venv
|
||
|
|
args:
|
||
|
|
creates: /opt/xray-lists/venv/bin/pip
|
||
|
|
|
||
|
|
- name: check if xray-lists is installed
|
||
|
|
ansible.builtin.command: /opt/xray-lists/venv/bin/pip show xray-lists
|
||
|
|
register: pip_check
|
||
|
|
changed_when: false
|
||
|
|
failed_when: false
|
||
|
|
|
||
|
|
- name: install xray-lists package into venv
|
||
|
|
ansible.builtin.command: /opt/xray-lists/venv/bin/pip install -e "/opt/xray-lists/xray-lists-src[socks]"
|
||
|
|
when: pip_check.rc != 0
|
||
|
|
|
||
|
|
- name: deploy helper scripts
|
||
|
|
ansible.builtin.copy:
|
||
|
|
src: "{{ item }}"
|
||
|
|
dest: "/opt/xray-lists/{{ item }}"
|
||
|
|
owner: root
|
||
|
|
group: root
|
||
|
|
mode: "0755"
|
||
|
|
loop:
|
||
|
|
- update.sh
|
||
|
|
- apply.sh
|
||
|
|
|
||
|
|
- name: deploy systemd service and timer unit
|
||
|
|
ansible.builtin.copy:
|
||
|
|
src: "{{ item }}"
|
||
|
|
dest: "/etc/systemd/system/{{ item }}"
|
||
|
|
owner: root
|
||
|
|
group: root
|
||
|
|
mode: "0644"
|
||
|
|
loop:
|
||
|
|
- xray-lists.service
|
||
|
|
- xray-lists.timer
|
||
|
|
notify: run xray-lists systemd timer unit
|
||
|
|
|
||
|
|
- name: ensure xray-lists config directory exists
|
||
|
|
ansible.builtin.file:
|
||
|
|
path: "/etc/xray-lists"
|
||
|
|
state: directory
|
||
|
|
owner: "root"
|
||
|
|
group: "root"
|
||
|
|
mode: "0755"
|
||
|
|
|
||
|
|
- name: render xray-lists config
|
||
|
|
ansible.builtin.template:
|
||
|
|
src: xray-config.yaml.j2
|
||
|
|
dest: /etc/xray-lists/config.yaml
|
||
|
|
owner: root
|
||
|
|
group: xray-lists
|
||
|
|
mode: "0640"
|
||
|
|
register: xray_lists_config
|
||
|
|
|
||
|
|
- name: update xray-lists
|
||
|
|
ansible.builtin.systemd_service:
|
||
|
|
name: xray-lists.service
|
||
|
|
state: started
|
||
|
|
when: xray_lists_config.changed
|