--- - name: Create temporary client config on server ansible.builtin.template: src: client.yaml.j2 dest: "/tmp/hysteria-client-{{ hysteria2_current_user.name }}.yaml" mode: "0600" - name: Get hysteria2:// URL via hysteria share ansible.builtin.command: cmd: >- hysteria share -c /tmp/hysteria-client-{{ hysteria2_current_user.name }}.yaml register: _hysteria2_share_url changed_when: false - name: Normalize share URL ansible.builtin.set_fact: _hysteria2_client_url: "{{ _hysteria2_share_url.stdout | trim | regex_replace('^hy2://', 'hysteria2://') }}" - name: Save URL to local file ansible.builtin.copy: dest: "{{ hysteria2_output_dir }}/{{ hysteria2_output_name }}/{{ hysteria2_current_user.name }}.url" mode: "0600" content: "{{ _hysteria2_client_url }}\n" delegate_to: localhost become: false - name: Save user info text file ansible.builtin.copy: dest: "{{ hysteria2_output_dir }}/{{ hysteria2_output_name }}/{{ hysteria2_current_user.name }}.txt" mode: "0600" content: | Server: {{ hysteria2_output_name }} Domain: {{ hysteria2_domain }}:{{ hysteria2_listen_port }} User: {{ hysteria2_current_user.name }} Password: {{ hysteria2_current_user.password }} Mode: salamander Obfs password: {{ hysteria2_obfs_password }} URL: {{ _hysteria2_client_url }} delegate_to: localhost become: false - name: Get ASCII QR code from hysteria share ansible.builtin.command: cmd: >- hysteria share -c /tmp/hysteria-client-{{ hysteria2_current_user.name }}.yaml --qr register: _hysteria2_share_qr changed_when: false - name: Save ASCII QR to local file ansible.builtin.copy: dest: "{{ hysteria2_output_dir }}/{{ hysteria2_output_name }}/{{ hysteria2_current_user.name }}.qr.txt" mode: "0600" content: | {{ _hysteria2_share_qr.stdout }} URL: {{ _hysteria2_client_url }} delegate_to: localhost become: false - name: Generate PNG QR code with qrencode on server when: hysteria2_generate_qr_png | bool block: - name: Write PNG QR code on server ansible.builtin.command: argv: - qrencode - -o - "/tmp/{{ hysteria2_current_user.name }}.png" - -s - "{{ hysteria2_qr_png_size | string }}" - -m - "{{ hysteria2_qr_png_margin | string }}" - -l - "{{ hysteria2_qr_png_error_correction }}" - "{{ _hysteria2_client_url }}" changed_when: true - name: Fetch PNG QR to control node ansible.builtin.fetch: src: "/tmp/{{ hysteria2_current_user.name }}.png" dest: "{{ hysteria2_output_dir }}/{{ hysteria2_output_name }}/" flat: true - name: Set permissions on local PNG QR ansible.builtin.file: path: "{{ hysteria2_output_dir }}/{{ hysteria2_output_name }}/{{ hysteria2_current_user.name }}.png" mode: "0600" delegate_to: localhost become: false - name: Remove temporary PNG QR on server ansible.builtin.file: path: "/tmp/{{ hysteria2_current_user.name }}.png" state: absent - name: Register user export data for HTML page ansible.builtin.set_fact: hysteria2_export_users: >- {{ hysteria2_export_users | default([]) + [{ 'name': hysteria2_current_user.name, 'password': hysteria2_current_user.password, 'url': _hysteria2_client_url, 'has_png': hysteria2_generate_qr_png | bool }] }} - name: Remove temporary client config from server ansible.builtin.file: path: "/tmp/hysteria-client-{{ hysteria2_current_user.name }}.yaml" state: absent