Files
hysteria2/roles/hysteria2/tasks/export_global.yml
T
Sergey Antropoff f6a81929b5 fix: пересборка output/index.html при uninstall с LIMIT
Второй play перенесён на hysteria2_servers с run_once на localhost,
чтобы LIMIT не пропускал пересборку. Пустой index.html удаляется.
2026-07-01 13:31:40 +03:00

98 lines
3.3 KiB
YAML

---
- name: Ensure output root directory exists
ansible.builtin.file:
path: "{{ hysteria2_output_dir }}"
state: directory
mode: "0700"
become: false
- name: Find server-info.yml in output directories
ansible.builtin.find:
paths: "{{ hysteria2_output_dir }}"
patterns: server-info.yml
recurse: true
register: _hysteria2_server_info_files
become: false
- name: Load server metadata from output
ansible.builtin.slurp:
src: "{{ item.path }}"
loop: "{{ _hysteria2_server_info_files.files | default([]) }}"
register: _hysteria2_server_info_raw
when: _hysteria2_server_info_files.matched | default(0) | int > 0
become: false
- name: Build global servers list
ansible.builtin.set_fact:
hysteria2_global_servers: "{{ hysteria2_global_servers | default([]) + [ _entry ] }}"
loop: "{{ _hysteria2_server_info_raw.results | default([]) }}"
when: not item.skipped | default(false)
vars:
_info: "{{ item.content | b64decode | from_yaml }}"
_entry:
name: "{{ _info.server }}"
domain: "{{ _info.domain }}"
port: "{{ _info.port }}"
dir: "{{ item.item.path | dirname | basename }}"
users: "{{ _info.users }}"
become: false
- name: Sort global servers by name
ansible.builtin.set_fact:
hysteria2_global_servers: "{{ hysteria2_global_servers | sort(attribute='name') }}"
when: hysteria2_global_servers | default([]) | length > 0
become: false
- name: Generate global HTML index
ansible.builtin.template:
src: export/global-index.html.j2
dest: "{{ hysteria2_output_dir }}/index.html"
mode: "0644"
vars:
generated_at: "{{ now(utc=false, fmt='%Y-%m-%d %H:%M:%S') }}"
total_users: "{{ hysteria2_global_servers | map(attribute='users') | map('length') | sum }}"
when: hysteria2_global_servers | default([]) | length > 0
become: false
- name: Remove global HTML index when no servers remain
ansible.builtin.file:
path: "{{ hysteria2_output_dir }}/index.html"
state: absent
when: hysteria2_global_servers | default([]) | length == 0
become: false
- name: Open global index in default browser (macOS)
ansible.builtin.command:
cmd: open "{{ hysteria2_output_dir }}/index.html"
when:
- hysteria2_open_browser | bool
- hysteria2_global_servers | default([]) | length > 0
- ansible_facts['system'] == 'Darwin'
changed_when: false
become: false
- name: Open global index in default browser (Linux)
ansible.builtin.command:
cmd: xdg-open "{{ hysteria2_output_dir }}/index.html"
when:
- hysteria2_open_browser | bool
- hysteria2_global_servers | default([]) | length > 0
- ansible_facts['system'] == 'Linux'
changed_when: false
become: false
failed_when: false
- name: Show global index location
ansible.builtin.debug:
msg: >-
Общий каталог: {{ hysteria2_output_dir }}/index.html
({% if hysteria2_open_browser | bool and hysteria2_global_servers | default([]) | length > 0 %}открыт в браузере{% else %}откройте вручную{% endif %})
when: hysteria2_global_servers | default([]) | length > 0
become: false
- name: Skip global index when no servers exported
ansible.builtin.debug:
msg: "Глобальный {{ hysteria2_output_dir }}/index.html удалён — нет server-info.yml в output/"
when: hysteria2_global_servers | default([]) | length == 0
become: false