diff --git a/roles/hysteria2/tasks/sync_install_script.yml b/roles/hysteria2/tasks/sync_install_script.yml index a1430e9..181f6a7 100644 --- a/roles/hysteria2/tasks/sync_install_script.yml +++ b/roles/hysteria2/tasks/sync_install_script.yml @@ -14,10 +14,19 @@ dest: "{{ hysteria2_install_script_staging_dir }}/{{ hysteria2_install_script_name }}.remote" mode: "0644" force: true + timeout: 30 delegate_to: localhost become: false run_once: true register: _hysteria2_remote_script + failed_when: false + +- name: Record install script fetch result + ansible.builtin.set_fact: + _hysteria2_script_fetch_ok: "{{ not (_hysteria2_remote_script.failed | default(false)) }}" + delegate_to: localhost + become: false + run_once: true - name: Stat local install script in role files ansible.builtin.stat: @@ -36,6 +45,7 @@ become: false run_once: true register: _hysteria2_remote_script_stat + when: _hysteria2_script_fetch_ok | bool - name: Update bundled install script when official version is newer ansible.builtin.copy: @@ -45,20 +55,55 @@ 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 + when: + - _hysteria2_script_fetch_ok | bool + - >- + 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: +- name: Fail when bundled install script is missing and official fetch failed + ansible.builtin.fail: msg: >- - {{ - 'Официальный install_server.sh обновлён в roles/hysteria2/files/' - if (_hysteria2_script_updated.changed | default(false)) - else 'Локальный install_server.sh актуален (совпадает с ' ~ hysteria2_install_script_url ~ ')' - }} + Не удалось скачать {{ hysteria2_install_script_url }} + ({{ _hysteria2_remote_script.msg | default('сеть недоступна') }}) + и локальный roles/hysteria2/files/{{ hysteria2_install_script_name }} отсутствует. delegate_to: localhost become: false run_once: true + when: + - not _hysteria2_script_fetch_ok | bool + - not _hysteria2_local_script.stat.exists + +- name: Report install script sync skipped due to network error + ansible.builtin.debug: + msg: >- + Пропуск синхронизации с {{ hysteria2_install_script_url }}: + {{ _hysteria2_remote_script.msg | default('сеть недоступна') }}. + Используется локальный roles/hysteria2/files/{{ hysteria2_install_script_name }}. + delegate_to: localhost + become: false + run_once: true + when: not _hysteria2_script_fetch_ok | bool + +- name: Report install script updated from official server + ansible.builtin.debug: + msg: Официальный install_server.sh обновлён в roles/hysteria2/files/ + delegate_to: localhost + become: false + run_once: true + when: + - _hysteria2_script_fetch_ok | bool + - _hysteria2_script_updated.changed | default(false) + +- name: Report install script already up to date + ansible.builtin.debug: + msg: >- + Локальный install_server.sh актуален (совпадает с {{ hysteria2_install_script_url }}). + delegate_to: localhost + become: false + run_once: true + when: + - _hysteria2_script_fetch_ok | bool + - not (_hysteria2_script_updated.changed | default(false))