-
Notifications
You must be signed in to change notification settings - Fork 12
/
auto-artifact-export.yml
96 lines (83 loc) · 2.94 KB
/
auto-artifact-export.yml
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
---
- name: Update dat files
hosts: all
become: yes
vars:
- base_path: /etc/mosdns
- restart_daemon: yes
- daemon_service_name: mosdns
- clean_up_after: yes
tasks:
- name: Check prerequisites
block:
- name: Gather package facts
ansible.builtin.package_facts:
manager: apt
- name: Install jq if jq is absent
ansible.builtin.apt:
name: jq
state: present
when: '"jq" not in ansible_facts.packages'
- name: Install curl if curl is absent
ansible.builtin.apt:
name: curl
state: present
when: '"curl" not in ansible_facts.packages'
- name: Install unzip if unzip is absent
apt:
name: unzip
state: present
when: '"unzip" not in ansible_facts.packages'
- name: Create project directories if not exist
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: 0755
loop:
- "{{ base_path }}/ips"
- "{{ base_path }}/domains"
- "{{ base_path }}/custom"
- "{{ base_path }}/downloads"
- name: Create cache file if not exist
ansible.builtin.file:
path: "{{ base_path }}/cache.dump"
state: file
mode: 0755
- name: Get latest release tag
shell: 'curl https://api.github.com/repos/techprober/v2ray-rules-dat/releases/latest --silent | jq -r ".tag_name"'
register: latest_release
- name: Print result
ansible.builtin.debug:
msg: |
"release_url: https://github.com/techprober/v2ray-rules-dat/releases/tag/{{ latest_release.stdout }}"
- name: Download dat files with the latest release
ansible.builtin.get_url:
url: "https://github.com/techprober/v2ray-rules-dat/releases/download/{{ latest_release.stdout }}/{{ item }}.zip"
dest: "{{ base_path }}/downloads/{{ item }}-{{ latest_release.stdout }}.zip"
loop:
- "geosite"
- "geoip"
register: download
- name: Unzip artifacts
block:
- name: Unzip geosite rules
shell: |
unzip -o {{ base_path }}/downloads/geosite-{{ latest_release.stdout }}.zip -d {{ base_path }}/domains
unzip -o {{ base_path }}/downloads/geoip-{{ latest_release.stdout }}.zip -d {{ base_path }}/ips
- name: Restart daemon service
ansible.builtin.service:
name: "{{ daemon_service_name }}"
state: restarted
when:
- restart_daemon
- download is changed
- name: Remove raw artifacts
ansible.builtin.file:
state: absent
path: "{{ item }}"
loop:
- "{{ base_path }}/downloads/geosite-{{ latest_release.stdout }}.zip"
- "{{ base_path }}/downloads/geoip-{{ latest_release.stdout }}.zip"
when:
- clean_up_after
- download is changed