feat: complete uninstall cleanup on server and local output
Remove binary, config, masq, system user, ufw rules, and apt packages from VPS; delete output/<server>/ by default and rebuild global index.html via localhost play. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -48,7 +48,7 @@ help: ## Показать справку
|
|||||||
@echo " make install"
|
@echo " make install"
|
||||||
@echo " make install LIMIT=vps-de"
|
@echo " make install LIMIT=vps-de"
|
||||||
@echo " make update LIMIT=vps-nl"
|
@echo " make update LIMIT=vps-nl"
|
||||||
@echo " make uninstall LIMIT=vps-de EXTRA_VARS='hysteria2_uninstall_remove_local_output=true'"
|
@echo " make uninstall LIMIT=vps-de"
|
||||||
@echo ""
|
@echo ""
|
||||||
|
|
||||||
init: ## Создать inventory, group_vars и .vault_pass из примеров
|
init: ## Создать inventory, group_vars и .vault_pass из примеров
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ make install # → output/index.html откроется в браузере
|
|||||||
| `make install` | Установка masquerade + экспорт URL/QR/HTML |
|
| `make install` | Установка masquerade + экспорт URL/QR/HTML |
|
||||||
| `make update` | Обновить бинарник, конфиг, перевыпустить экспорт |
|
| `make update` | Обновить бинарник, конфиг, перевыпустить экспорт |
|
||||||
| `make export` | Только экспорт (URL, QR, HTML) |
|
| `make export` | Только экспорт (URL, QR, HTML) |
|
||||||
| `make uninstall` | Удалить Hysteria2 с VPS |
|
| `make uninstall` | Полное удаление Hysteria2 с VPS + `output/<server>/` + пересборка `output/index.html` |
|
||||||
| `make vault-encrypt` | Зашифровать vault |
|
| `make vault-encrypt` | Зашифровать vault |
|
||||||
| `make vault-edit` | Редактировать vault |
|
| `make vault-edit` | Редактировать vault |
|
||||||
|
|
||||||
@@ -71,7 +71,8 @@ make install # → output/index.html откроется в браузере
|
|||||||
make install LIMIT=vps-de
|
make install LIMIT=vps-de
|
||||||
make update LIMIT=vps-nl
|
make update LIMIT=vps-nl
|
||||||
make export
|
make export
|
||||||
make uninstall LIMIT=vps-de EXTRA_VARS='hysteria2_uninstall_remove_local_output=true'
|
make uninstall LIMIT=vps-de
|
||||||
|
make uninstall LIMIT=vps-de EXTRA_VARS='hysteria2_uninstall_remove_local_output=false'
|
||||||
make install EXTRA_VARS='hysteria2_open_browser=false'
|
make install EXTRA_VARS='hysteria2_open_browser=false'
|
||||||
make update EXTRA_VARS='hysteria2_wait_for_acme=false'
|
make update EXTRA_VARS='hysteria2_wait_for_acme=false'
|
||||||
```
|
```
|
||||||
@@ -284,7 +285,8 @@ ASCII QR — `hysteria share --qr` → `user.qr.txt`.
|
|||||||
| `hysteria2_listen_port` | group | Порт Hysteria2 (443) |
|
| `hysteria2_listen_port` | group | Порт Hysteria2 (443) |
|
||||||
| `hysteria2_generate_qr_png` | group | PNG QR через `qrencode` |
|
| `hysteria2_generate_qr_png` | group | PNG QR через `qrencode` |
|
||||||
| `hysteria2_open_browser` | group | Открыть `output/index.html` после экспорта |
|
| `hysteria2_open_browser` | group | Открыть `output/index.html` после экспорта |
|
||||||
| `hysteria2_uninstall_remove_local_output` | extra-vars | Удалить `output/<server>/` при uninstall |
|
| `hysteria2_uninstall_remove_local_output` | group | Удалить `output/<server>/` при uninstall (по умолчанию `true`) |
|
||||||
|
| `hysteria2_uninstall_rebuild_global_index` | group | Пересобрать `output/index.html` после uninstall (по умолчанию `true`) |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -5,3 +5,16 @@
|
|||||||
roles:
|
roles:
|
||||||
- role: hysteria2
|
- role: hysteria2
|
||||||
tags: [uninstall]
|
tags: [uninstall]
|
||||||
|
|
||||||
|
- name: Rebuild global output index after uninstall
|
||||||
|
hosts: localhost
|
||||||
|
connection: local
|
||||||
|
gather_facts: true
|
||||||
|
become: false
|
||||||
|
tags: [uninstall]
|
||||||
|
tasks:
|
||||||
|
- name: Regenerate output/index.html from remaining servers
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: hysteria2
|
||||||
|
tasks_from: export_global.yml
|
||||||
|
when: hysteria2_uninstall_rebuild_global_index | default(true) | bool
|
||||||
|
|||||||
@@ -41,8 +41,3 @@ hysteria2_wait_for_acme: true
|
|||||||
|
|
||||||
# Открыть output/index.html в браузере после install/update/export
|
# Открыть output/index.html в браузере после install/update/export
|
||||||
hysteria2_open_browser: true
|
hysteria2_open_browser: true
|
||||||
|
|
||||||
# --- uninstall ---
|
|
||||||
hysteria2_uninstall_remove_config: true
|
|
||||||
hysteria2_uninstall_remove_masq: true
|
|
||||||
hysteria2_uninstall_remove_local_output: false
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
# Системный пользователь Hysteria (создаётся install_server.sh)
|
||||||
|
hysteria2_system_user: hysteria
|
||||||
|
|
||||||
|
# --- uninstall ---
|
||||||
|
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,14 +6,23 @@
|
|||||||
state: stopped
|
state: stopped
|
||||||
failed_when: false
|
failed_when: false
|
||||||
|
|
||||||
- name: Remove Hysteria2 via official script
|
- name: Sync official Hysteria2 install script on control node
|
||||||
ansible.builtin.shell:
|
ansible.builtin.import_tasks: sync_install_script.yml
|
||||||
cmd: bash <(curl -fsSL https://get.hy2.sh/) --remove
|
|
||||||
executable: /bin/bash
|
- name: Copy Hysteria2 install script to server
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: "{{ hysteria2_install_script_name }}"
|
||||||
|
dest: "{{ hysteria2_install_script_remote_path }}"
|
||||||
|
mode: "0755"
|
||||||
|
|
||||||
|
- name: Remove Hysteria2 binary and systemd units via official script
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: "{{ hysteria2_install_script_remote_path }} --remove"
|
||||||
register: _hysteria2_remove
|
register: _hysteria2_remove
|
||||||
|
changed_when: _hysteria2_remove.rc == 0
|
||||||
failed_when: false
|
failed_when: false
|
||||||
|
|
||||||
- name: Remove Hysteria2 configuration directory
|
- name: Remove Hysteria2 configuration and ACME data
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ hysteria2_config_path | dirname }}"
|
path: "{{ hysteria2_config_path | dirname }}"
|
||||||
state: absent
|
state: absent
|
||||||
@@ -25,18 +34,57 @@
|
|||||||
state: absent
|
state: absent
|
||||||
when: hysteria2_uninstall_remove_masq | bool
|
when: hysteria2_uninstall_remove_masq | bool
|
||||||
|
|
||||||
|
- name: Remove Hysteria system user and home directory
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: "{{ hysteria2_system_user }}"
|
||||||
|
state: absent
|
||||||
|
remove: true
|
||||||
|
when: hysteria2_uninstall_remove_system_user | bool
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
|
- name: Check if ufw is available and active
|
||||||
|
ansible.builtin.command: ufw status
|
||||||
|
register: _hysteria2_ufw_status
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
when: hysteria2_uninstall_remove_firewall_rules | bool
|
||||||
|
|
||||||
|
- name: Remove firewall rules added during install
|
||||||
|
ansible.builtin.command: "ufw delete allow {{ item }}"
|
||||||
|
loop: "{{ hysteria2_uninstall_ufw_rules }}"
|
||||||
|
register: _hysteria2_ufw_delete
|
||||||
|
changed_when: >-
|
||||||
|
_hysteria2_ufw_delete.rc == 0
|
||||||
|
and 'Could not delete' not in (_hysteria2_ufw_delete.stdout | default(''))
|
||||||
|
and 'Could not find' not in (_hysteria2_ufw_delete.stderr | default(''))
|
||||||
|
failed_when: false
|
||||||
|
when:
|
||||||
|
- hysteria2_uninstall_remove_firewall_rules | bool
|
||||||
|
- "'active' in (_hysteria2_ufw_status.stdout | default(''))"
|
||||||
|
|
||||||
|
- name: Remove packages installed for Hysteria2
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: "{{ _hysteria2_apt_packages }}"
|
||||||
|
state: absent
|
||||||
|
purge: true
|
||||||
|
autoremove: true
|
||||||
|
vars:
|
||||||
|
_hysteria2_apt_packages: >-
|
||||||
|
{{
|
||||||
|
['curl', 'micro']
|
||||||
|
+ (['qrencode'] if hysteria2_generate_qr_png | bool else [])
|
||||||
|
}}
|
||||||
|
when: hysteria2_uninstall_remove_packages | bool
|
||||||
|
|
||||||
|
- name: Remove copied install script from server
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ hysteria2_install_script_remote_path }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: Reload systemd after uninstall
|
- name: Reload systemd after uninstall
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
daemon_reload: true
|
daemon_reload: true
|
||||||
|
|
||||||
- name: Show uninstall result
|
|
||||||
ansible.builtin.debug:
|
|
||||||
msg: >-
|
|
||||||
Hysteria2 удалён с {{ inventory_hostname }}.
|
|
||||||
{% if not hysteria2_uninstall_remove_local_output | bool %}
|
|
||||||
Локальные URL/QR в {{ hysteria2_output_dir }}/{{ hysteria2_output_name }}/ сохранены.
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
- name: Remove local exported client files
|
- name: Remove local exported client files
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ hysteria2_output_dir }}/{{ hysteria2_output_name }}"
|
path: "{{ hysteria2_output_dir }}/{{ hysteria2_output_name }}"
|
||||||
@@ -44,3 +92,16 @@
|
|||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
become: false
|
become: false
|
||||||
when: hysteria2_uninstall_remove_local_output | bool
|
when: hysteria2_uninstall_remove_local_output | bool
|
||||||
|
|
||||||
|
- name: Show uninstall result
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: >-
|
||||||
|
Hysteria2 полностью удалён с {{ inventory_hostname }}.
|
||||||
|
{% if hysteria2_uninstall_remove_local_output | bool %}
|
||||||
|
Локальные URL/QR в {{ hysteria2_output_dir }}/{{ hysteria2_output_name }}/ удалены.
|
||||||
|
{% if hysteria2_uninstall_rebuild_global_index | bool %}
|
||||||
|
Глобальный {{ hysteria2_output_dir }}/index.html пересобран.
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
Локальные URL/QR в {{ hysteria2_output_dir }}/{{ hysteria2_output_name }}/ сохранены.
|
||||||
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user