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:
@@ -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)
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
- name: Uninstall Hysteria2 servers
|
||||
hosts: hysteria2_servers
|
||||
gather_facts: false
|
||||
roles:
|
||||
- role: hysteria2
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 }}/ сохранены.
|
||||
|
||||
Reference in New Issue
Block a user