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