From 5d0d3e49a0bb4b9679e242448ad04d05109b41e4 Mon Sep 17 00:00:00 2001 From: Sergey Antropoff Date: Wed, 1 Jul 2026 13:19:47 +0300 Subject: [PATCH] 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 --- Makefile | 2 +- playbook-uninstall.yml | 9 ++++++--- roles/hysteria2/defaults/main.yml | 12 ++++++++++++ roles/hysteria2/tasks/uninstall.yml | 27 ++++++++++++--------------- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index d834e09..782380e 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/playbook-uninstall.yml b/playbook-uninstall.yml index 51a39d2..5a30083 100644 --- a/playbook-uninstall.yml +++ b/playbook-uninstall.yml @@ -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 diff --git a/roles/hysteria2/defaults/main.yml b/roles/hysteria2/defaults/main.yml index eccf54b..839537f 100644 --- a/roles/hysteria2/defaults/main.yml +++ b/roles/hysteria2/defaults/main.yml @@ -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" diff --git a/roles/hysteria2/tasks/uninstall.yml b/roles/hysteria2/tasks/uninstall.yml index f43e229..2ed5d4b 100644 --- a/roles/hysteria2/tasks/uninstall.yml +++ b/roles/hysteria2/tasks/uninstall.yml @@ -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 }}/ сохранены.