blob: d488953121770d6682a2beab26b57715d0f32d05 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
---
- name: "create directory"
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: _vpn
group: _vpn
mode: 0700
loop:
- "/var/reactance/xray"
- "/var/reactance/xray/bin"
- "/var/reactance/xray/etc"
- "/var/reactance/xray/logs"
- "/var/log/xray"
- name: "install golang to build xray"
community.general.openbsd_pkg:
name: go--
state: present
register: installed_go
- name: "log var"
ansible.builtin.debug:
msg: "{{ is_installed }}"
- name: "create temporary directory"
ansible.builtin.tempfile:
state: directory
suffix: temp
register: xray_tempdir
notify:
- remove_xray_tempdir
- name: "get latest version"
ansible.builtin.shell: 'curl --silent "https://api.github.com/repos/XTLS/Xray-core/releases/latest" | jq -r .tag_name'
register: xray_latest_version
- name: "download latest source"
ansible.builtin.get_url:
url: "https://github.com/XTLS/Xray-core/releases/download/{{ xray_latest_version.stdout }}/{{ xray_latest_version.stdout }}.zip"
dest: "{{ xray_tempdir.path }}/source.zip"
- name: "additionally download latest version (for geoip.dat, geosite.dat)"
ansible.builtin.get_url:
url: "https://github.com/XTLS/Xray-core/releases/download/{{ xray_latest_version.stdout }}/Xray-openbsd-64.zip"
dest: "{{ xray_tempdir.path }}/xray.zip"
- name: "unzip xray"
ansible.builtin.unarchive:
src: "{{ xray_tempdir.path }}/xray.zip"
dest: "{{ xray_tempdir.path }}"
remote_src: yes
- name: "unzip xray source"
ansible.builtin.unarchive:
src: "{{ xray_tempdir.path }}/xray.source"
dest: "{{ xray_tempdir.path }}/source"
remote_src: yes
- name: "build xray from source"
ansible.builtin.shell: "CGO_ENABLED=0 go build -o xray -trimpath -buildvcs=false -ldflags=\"-s -w -buildid= -X 'xray.buf.readv='\" ./main"
args:
chdir: "{{ xray_tempdir.path }}/source"
- name: "template out init script"
ansible.builtin.template:
src: "{{ item.file_src }}"
dest: "{{ item.file_dest }}"
loop:
- file_src: xray.rc.j2
file_dest: "{{ xray_tempdir.path }}/xray.rc"
- name: "install xray"
ansible.builtin.shell: "{{ item }}"
loop:
- "install -m 700 -o _vpn -g bin {{ xray_tempdir.path }}/source/xray /var/reactance/xray/bin/xray"
- "install -m 755 -o _vpn -g bin {{ xray_tempdir.path }}/xray.rc /etc/rc.d/xray"
- "install -m 700 -o _vpn -g bin {{ xray_tempdir.path }}/geoip.dat /var/reactance/xray/bin/geoip.dat"
- "install -m 700 -o _vpn -g bin {{ xray_tempdir.path }}/geosite.dat /var/reactance/xray/bin/geosite.dat"
- name: "copy chroot dependencies"
ansible.builtin.shell: "deps=$(ldd /var/reactance/xray/bin/xray | awk 'FNR > 3 {print $7}'); for dep in $deps; do rsync -av --relative $dep /var/reactance/xray; done"
# xray will fail without these two files
- name: "copy hosts and resolv.conf"
ansible.builtin.copy:
remote_src: true
src: "{{ item.src }}"
dest: "{{ item.dest }}"
loop:
- src: /etc/hosts
dest: /var/reactance/xray/etc/hosts
- src: /etc/resolv.conf
dest: /var/reactance/xray/etc/resolv.conf
# - name: "uninstall golang (if wasn't installed in past)"
# community.general.openbsd_pkg:
# name: go--
# state: present
|