Files
hysteria2/roles/hysteria2/tasks/uninstall.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

138 lines
4.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
- name: Stop and disable hysteria-server before removal
ansible.builtin.systemd:
name: "{{ hysteria2_service_name }}"
enabled: false
state: stopped
failed_when: false
- name: Copy Hysteria2 install script to server
ansible.builtin.copy:
src: "{{ hysteria2_install_script_name }}"
dest: "{{ hysteria2_install_script_remote_path }}"
mode: "0755"
- name: Remove Hysteria2 binary and systemd units via official script
ansible.builtin.command:
cmd: "{{ hysteria2_install_script_remote_path }} --remove"
register: _hysteria2_remove
changed_when: _hysteria2_remove.rc == 0
failed_when: false
- name: Show official script removal output
ansible.builtin.debug:
msg: "{{ _hysteria2_remove.stdout_lines | default(['install_server.sh --remove: no output']) }}"
when: _hysteria2_remove.stdout_lines is defined
- name: Remove Hysteria2 configuration and ACME data
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop:
- "{{ hysteria2_config_path | dirname }}"
- "/var/lib/{{ hysteria2_system_user | default('hysteria') }}"
- name: Remove masquerade web directory
ansible.builtin.file:
path: "{{ hysteria2_masq_dir }}"
state: absent
when: hysteria2_uninstall_remove_masq | default(true) | bool
- name: Remove enabled hysteria-server systemd symlink
ansible.builtin.file:
path: /etc/systemd/system/multi-user.target.wants/hysteria-server.service
state: absent
failed_when: false
- name: Find enabled hysteria-server@ systemd symlinks
ansible.builtin.find:
paths: /etc/systemd/system/multi-user.target.wants
patterns: hysteria-server@*.service
file_type: file
register: _hysteria2_systemd_instance_wants
failed_when: false
- name: Remove enabled hysteria-server@ systemd symlinks
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ _hysteria2_systemd_instance_wants.files | default([]) }}"
failed_when: false
- name: Remove Hysteria system user and home directory
ansible.builtin.user:
name: "{{ hysteria2_system_user | default('hysteria') }}"
state: absent
remove: true
failed_when: false
- name: Find temporary Hysteria client configs on server
ansible.builtin.find:
paths: /tmp
patterns: hysteria-client-*.yaml
file_type: file
register: _hysteria2_tmp_client_configs
failed_when: false
- name: Remove temporary Hysteria client configs on server
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ _hysteria2_tmp_client_configs.files | default([]) }}"
failed_when: false
- name: Check if ufw is available and active
ansible.builtin.command: ufw status
register: _hysteria2_ufw_status
changed_when: false
failed_when: false
- name: Remove firewall rules added during install
ansible.builtin.command: "ufw delete allow {{ item }}"
loop: "{{ hysteria2_uninstall_ufw_rules }}"
register: _hysteria2_ufw_delete
changed_when: >-
_hysteria2_ufw_delete.rc == 0
and 'Could not delete' not in (_hysteria2_ufw_delete.stdout | default(''))
and 'Could not find' not in (_hysteria2_ufw_delete.stderr | default(''))
failed_when: false
when: "'active' in (_hysteria2_ufw_status.stdout | default(''))"
- name: Remove packages installed for Hysteria2
ansible.builtin.apt:
name: "{{ _hysteria2_apt_packages }}"
state: absent
purge: true
autoremove: true
vars:
_hysteria2_apt_packages: >-
{{
['curl', 'micro']
+ (['qrencode'] if hysteria2_generate_qr_png | default(true) | bool else [])
}}
- name: Remove copied install script from server
ansible.builtin.file:
path: "{{ hysteria2_install_script_remote_path }}"
state: absent
- name: Reload systemd after uninstall
ansible.builtin.systemd:
daemon_reload: true
- name: Remove local output directory for this server
ansible.builtin.file:
path: "{{ hysteria2_output_dir }}/{{ hysteria2_output_name }}"
state: absent
delegate_to: localhost
become: false
- name: Show uninstall result
ansible.builtin.debug:
msg: >-
Hysteria2 полностью удалён с {{ inventory_hostname }}.
Локальная папка {{ hysteria2_output_dir }}/{{ hysteria2_output_name }}/ удалена.
{% if hysteria2_uninstall_rebuild_global_index | default(true) | bool %}
{{ hysteria2_output_dir }}/index.html будет пересобран без этого сервера.
{% endif %}