fix: run only uninstall tasks, not full role on make uninstall

Tagging the whole role with uninstall caused install/configure/update/export to run first. Use include_role tasks_from uninstall.yml; add safe defaults for uninstall variables.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Sergey Antropoff
2026-07-01 13:19:47 +03:00
parent f5939c48fc
commit 5d0d3e49a0
4 changed files with 31 additions and 19 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ update: check ## Обновить бинарник, перекатить кон
export: check ## Только перевыпустить URL и QR (без изменений на сервере)
$(ANSIBLE) playbook.yml --tags export $(ANSIBLE_OPTS)
uninstall: ## Удалить Hysteria2 с VPS
uninstall: ## Полностью удалить Hysteria2 с VPS (только uninstall, без install/update)
@echo "$(YELLOW)Будет выполнено удаление Hysteria2$(NC) $(if $(LIMIT),на $(LIMIT),на всех серверах)"
@read -p "Продолжить? [y/N] " c; [[ "$$c" =~ ^[Yy]$$ ]] || exit 1
$(ANSIBLE) playbook-uninstall.yml --tags uninstall $(ANSIBLE_OPTS)
+6 -3
View File
@@ -2,9 +2,12 @@
- name: Uninstall Hysteria2 servers
hosts: hysteria2_servers
gather_facts: false
roles:
- role: hysteria2
tags: [uninstall]
tags: [uninstall]
tasks:
- name: Run Hysteria2 uninstall tasks only
ansible.builtin.include_role:
name: hysteria2
tasks_from: uninstall.yml
- name: Rebuild global output index after uninstall
hosts: localhost
+12
View File
@@ -46,3 +46,15 @@ hysteria2_open_browser: true
# Перегенерировать URL/QR для всех пользователей (иначе — только новые/изменённые)
hysteria2_force_export: false
# --- uninstall (см. также defaults/uninstall.yml) ---
hysteria2_system_user: hysteria
hysteria2_uninstall_remove_config: true
hysteria2_uninstall_remove_masq: false
hysteria2_uninstall_remove_system_user: true
hysteria2_uninstall_remove_packages: true
hysteria2_uninstall_remove_firewall_rules: true
hysteria2_uninstall_remove_local_output: true
hysteria2_uninstall_rebuild_global_index: true
hysteria2_uninstall_ufw_rules:
- "{{ hysteria2_listen_port }}/tcp"
- "{{ hysteria2_listen_port }}/udp"
+12 -15
View File
@@ -6,10 +6,7 @@
state: stopped
failed_when: false
- name: Sync official Hysteria2 install script on control node
ansible.builtin.import_tasks: sync_install_script.yml
- name: Copy Hysteria2 install script to server
- name: Copy Hysteria2 install script to server for removal
ansible.builtin.copy:
src: "{{ hysteria2_install_script_name }}"
dest: "{{ hysteria2_install_script_remote_path }}"
@@ -26,14 +23,14 @@
ansible.builtin.file:
path: "{{ hysteria2_config_path | dirname }}"
state: absent
when: hysteria2_uninstall_remove_config | bool
when: hysteria2_uninstall_remove_config | default(true) | bool
- name: Remove Hysteria system user and home directory
ansible.builtin.user:
name: "{{ hysteria2_system_user }}"
name: "{{ hysteria2_system_user | default('hysteria') }}"
state: absent
remove: true
when: hysteria2_uninstall_remove_system_user | bool
when: hysteria2_uninstall_remove_system_user | default(true) | bool
failed_when: false
- name: Check if ufw is available and active
@@ -41,7 +38,7 @@
register: _hysteria2_ufw_status
changed_when: false
failed_when: false
when: hysteria2_uninstall_remove_firewall_rules | bool
when: hysteria2_uninstall_remove_firewall_rules | default(true) | bool
- name: Remove firewall rules added during install
ansible.builtin.command: "ufw delete allow {{ item }}"
@@ -53,7 +50,7 @@
and 'Could not find' not in (_hysteria2_ufw_delete.stderr | default(''))
failed_when: false
when:
- hysteria2_uninstall_remove_firewall_rules | bool
- hysteria2_uninstall_remove_firewall_rules | default(true) | bool
- "'active' in (_hysteria2_ufw_status.stdout | default(''))"
- name: Remove packages installed for Hysteria2
@@ -66,9 +63,9 @@
_hysteria2_apt_packages: >-
{{
['curl', 'micro']
+ (['qrencode'] if hysteria2_generate_qr_png | bool else [])
+ (['qrencode'] if hysteria2_generate_qr_png | default(true) | bool else [])
}}
when: hysteria2_uninstall_remove_packages | bool
when: hysteria2_uninstall_remove_packages | default(true) | bool
- name: Remove copied install script from server
ansible.builtin.file:
@@ -85,16 +82,16 @@
state: absent
delegate_to: localhost
become: false
when: hysteria2_uninstall_remove_local_output | bool
when: hysteria2_uninstall_remove_local_output | default(true) | bool
- name: Show uninstall result
ansible.builtin.debug:
msg: >-
Hysteria2 (Salamander) полностью удалён с {{ inventory_hostname }}.
{% if hysteria2_uninstall_remove_local_output | bool %}
{% if hysteria2_uninstall_remove_local_output | default(true) | bool %}
Локальные URL/QR в {{ hysteria2_output_dir }}/{{ hysteria2_output_name }}/ удалены.
{% if hysteria2_uninstall_rebuild_global_index | bool %}
Глобальный {{ hysteria2_output_dir }}/index.html пересобран.
{% if hysteria2_uninstall_rebuild_global_index | default(true) | bool %}
Глобальный {{ hysteria2_output_dir }}/index.html будет пересобран.
{% endif %}
{% else %}
Локальные URL/QR в {{ hysteria2_output_dir }}/{{ hysteria2_output_name }}/ сохранены.