Compare commits

..

2 Commits

Author SHA1 Message Date
Sergey Antropoff b9284f280f feat: bundle and sync official Hysteria2 install script locally
Store install_server.sh in role files, compare SHA256 with get.hy2.sh on the control node before install/update, refresh the bundled copy when upstream changes, then copy and run it on VPS.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-01 12:00:37 +03:00
Sergey Antropoff b83b69d309 fix: disable become on localhost play and drop deprecated facts
Use now() for export timestamps and ansible_facts['system'] for browser detection. Set become: false on the localhost play to avoid sudo on local fact gathering.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-01 11:56:18 +03:00
8 changed files with 1267 additions and 11 deletions
+1
View File
@@ -9,6 +9,7 @@
hosts: localhost
connection: local
gather_facts: true
become: false
tags: [install, update, export]
tasks:
- name: Generate global index.html and open in browser
+6
View File
@@ -26,6 +26,12 @@ hysteria2_configure_firewall: true
hysteria2_config_path: /etc/hysteria/config.yaml
hysteria2_service_name: hysteria-server
# Официальный install_server.sh: хранится в roles/hysteria2/files/, синхронизируется с get.hy2.sh
hysteria2_install_script_url: "https://get.hy2.sh/"
hysteria2_install_script_name: install_server.sh
hysteria2_install_script_staging_dir: "{{ playbook_dir }}/.cache/hysteria2"
hysteria2_install_script_remote_path: /tmp/hysteria2-install_server.sh
hysteria2_output_dir: "{{ playbook_dir }}/output"
hysteria2_output_name: "{{ inventory_hostname }}"
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -54,7 +54,7 @@
dest: "{{ hysteria2_output_dir }}/{{ hysteria2_output_name }}/index.html"
mode: "0644"
vars:
generated_at: "{{ ansible_date_time.date }} {{ ansible_date_time.time }}"
generated_at: "{{ now(utc=false, fmt='%Y-%m-%d %H:%M:%S') }}"
hysteria2_obfs_password: "{{ hysteria2_obfs_password }}"
delegate_to: localhost
become: false
+3 -3
View File
@@ -51,7 +51,7 @@
dest: "{{ hysteria2_output_dir }}/index.html"
mode: "0644"
vars:
generated_at: "{{ ansible_date_time.date }} {{ ansible_date_time.time }}"
generated_at: "{{ now(utc=false, fmt='%Y-%m-%d %H:%M:%S') }}"
total_users: "{{ hysteria2_global_servers | map(attribute='users') | map('length') | sum }}"
when: hysteria2_global_servers | default([]) | length > 0
become: false
@@ -62,7 +62,7 @@
when:
- hysteria2_open_browser | bool
- hysteria2_global_servers | default([]) | length > 0
- ansible_system == 'Darwin'
- ansible_facts['system'] == 'Darwin'
changed_when: false
become: false
@@ -72,7 +72,7 @@
when:
- hysteria2_open_browser | bool
- hysteria2_global_servers | default([]) | length > 0
- ansible_system == 'Linux'
- ansible_facts['system'] == 'Linux'
changed_when: false
become: false
failed_when: false
+11 -4
View File
@@ -23,11 +23,18 @@
+ (['qrencode'] if hysteria2_generate_qr_png | bool else [])
}}
- name: Sync official Hysteria2 install script on control node
ansible.builtin.import_tasks: sync_install_script.yml
- name: Copy Hysteria2 install script to server
ansible.builtin.copy:
src: "{{ hysteria2_install_script_name }}"
dest: "{{ hysteria2_install_script_remote_path }}"
mode: "0755"
- name: Install Hysteria2 via official script
ansible.builtin.shell:
cmd: bash <(curl -fsSL https://get.hy2.sh/)
executable: /bin/bash
args:
ansible.builtin.command:
cmd: "{{ hysteria2_install_script_remote_path }}"
creates: /usr/local/bin/hysteria
register: _hysteria2_install
@@ -0,0 +1,64 @@
---
- name: Ensure staging directory for install script sync
ansible.builtin.file:
path: "{{ hysteria2_install_script_staging_dir }}"
state: directory
mode: "0700"
delegate_to: localhost
become: false
run_once: true
- name: Fetch official install script for version check
ansible.builtin.get_url:
url: "{{ hysteria2_install_script_url }}"
dest: "{{ hysteria2_install_script_staging_dir }}/{{ hysteria2_install_script_name }}.remote"
mode: "0644"
force: true
delegate_to: localhost
become: false
run_once: true
register: _hysteria2_remote_script
- name: Stat local install script in role files
ansible.builtin.stat:
path: "{{ role_path }}/files/{{ hysteria2_install_script_name }}"
checksum_algorithm: sha256
delegate_to: localhost
become: false
run_once: true
register: _hysteria2_local_script
- name: Stat remote install script from official server
ansible.builtin.stat:
path: "{{ hysteria2_install_script_staging_dir }}/{{ hysteria2_install_script_name }}.remote"
checksum_algorithm: sha256
delegate_to: localhost
become: false
run_once: true
register: _hysteria2_remote_script_stat
- name: Update bundled install script when official version is newer
ansible.builtin.copy:
src: "{{ hysteria2_install_script_staging_dir }}/{{ hysteria2_install_script_name }}.remote"
dest: "{{ role_path }}/files/{{ hysteria2_install_script_name }}"
mode: "0755"
delegate_to: localhost
become: false
run_once: true
when: >-
not _hysteria2_local_script.stat.exists
or _hysteria2_local_script.stat.checksum
!= _hysteria2_remote_script_stat.stat.checksum
register: _hysteria2_script_updated
- name: Report install script sync result
ansible.builtin.debug:
msg: >-
{{
'Официальный install_server.sh обновлён в roles/hysteria2/files/'
if (_hysteria2_script_updated.changed | default(false))
else 'Локальный install_server.sh актуален (совпадает с ' ~ hysteria2_install_script_url ~ ')'
}}
delegate_to: localhost
become: false
run_once: true
+11 -3
View File
@@ -1,8 +1,16 @@
---
- name: Sync official Hysteria2 install script on control node
ansible.builtin.import_tasks: sync_install_script.yml
- name: Copy Hysteria2 install script to server
ansible.builtin.copy:
src: "{{ hysteria2_install_script_name }}"
dest: "{{ hysteria2_install_script_remote_path }}"
mode: "0755"
- name: Update Hysteria2 binary via official script
ansible.builtin.shell:
cmd: bash <(curl -fsSL https://get.hy2.sh/)
executable: /bin/bash
ansible.builtin.command:
cmd: "{{ hysteria2_install_script_remote_path }} --force"
register: _hysteria2_update
notify: Restart hysteria-server