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 05994fceaf
commit 27ae65edc5
4 changed files with 34 additions and 20 deletions
+14
View File
@@ -44,3 +44,17 @@ 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: true
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:
- 80/tcp
- 443/tcp
- 443/udp
+13 -16
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,20 +23,20 @@
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 masquerade web directory
ansible.builtin.file:
path: "{{ hysteria2_masq_dir }}"
state: absent
when: hysteria2_uninstall_remove_masq | bool
when: hysteria2_uninstall_remove_masq | 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
@@ -47,7 +44,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 }}"
@@ -59,7 +56,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
@@ -72,9 +69,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:
@@ -91,16 +88,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 полностью удалён с {{ 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 }}/ сохранены.