Skip to content

Instantly share code, notes, and snippets.

@z-x-f
Forked from piyoki/auto-artifact-export.yml
Created July 9, 2023 12:46
Show Gist options
  • Select an option

  • Save z-x-f/d481adb2c9eb8ddc438bccfa45966da4 to your computer and use it in GitHub Desktop.

Select an option

Save z-x-f/d481adb2c9eb8ddc438bccfa45966da4 to your computer and use it in GitHub Desktop.
mosdns-v5 config template
---
# auto-artifact-export.yml
# Ansible playbook that updates geo-rules for mosdns
- name: Update dat files
hosts: all
become: yes
vars:
- dest_path: /etc/mosdns
- restart_daemon: yes
- daemon_service_name: mosdns
tasks:
- name: Check prerequisites
block:
- name: Gather package facts
package_facts:
manager: apt
- name: Install jq if jq is absent
apt:
name: jq
state: present
when: '"jq" not in ansible_facts.packages'
- name: Create project directories if not exist
file:
path: "{{ item }}"
state: directory
mode: 0755
loop:
- "{{ dest_path }}/ips"
- "{{ dest_path }}/domains"
- "{{ dest_path }}/custom"
- "{{ dest_path }}/downloads"
- 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
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: "{{ item }}"
dest: "{{ dest_path }}/downloads"
loop:
- "https://github.com/techprober/v2ray-rules-dat/releases/download/{{ latest_release.stdout }}/geosite.zip"
- "https://github.com/techprober/v2ray-rules-dat/releases/download/{{ latest_release.stdout }}/geoip.zip"
- name: Unzip artifacts
block:
- name: Unzip geosite rules
ansible.builtin.unarchive:
src: "{{ dest_path }}/downloads/geosite.zip"
dest: "{{ dest_path }}/domains/"
remote_src: yes
- name: Unzip geoip rules
ansible.builtin.unarchive:
src: "{{ dest_path }}/downloads/geoip.zip"
dest: "{{ dest_path }}/ips/"
remote_src: yes
- name: Restart daemon service
ansible.builtin.service:
name: "{{ daemon_service_name }}"
state: restarted
when: restart_daemon
---
- name: Update dat files
hosts: all
become: yes
vars:
- dest_path: /etc/mosdns
- restart_daemon: yes
- daemon_service_name: mosdns
tasks:
- name: Check prerequisites
block:
- name: Gather package facts
package_facts:
manager: apt
- name: Install jq if jq is absent
apt:
name: jq
state: present
when: '"jq" not in ansible_facts.packages'
- name: Create project directories if not exist
file:
path: "{{ item }}"
state: directory
mode: 0755
loop:
- "{{ dest_path }}/ips"
- "{{ dest_path }}/domains"
- "{{ dest_path }}/custom"
- "{{ dest_path }}/downloads"
- 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
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 }}"
dest: "{{ dest_path }}/downloads"
loop:
- "geosite.zip"
- "geoip.zip"
register: download
- name: Unzip artifacts
block:
- name: Unzip geosite rules
ansible.builtin.unarchive:
src: "{{ dest_path }}/downloads/geosite.zip"
dest: "{{ dest_path }}/domains/"
remote_src: yes
- name: Unzip geoip rules
ansible.builtin.unarchive:
src: "{{ dest_path }}/downloads/geoip.zip"
dest: "{{ dest_path }}/ips/"
remote_src: yes
- name: Restart daemon service
ansible.builtin.service:
name: "{{ daemon_service_name }}"
state: restarted
when:
- restart_daemon
- download is changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment