--- - name: "Change the hostname to {{ inventory_hostname }}" ansible.windows.win_hostname: name: "{{ inventory_hostname }}" register: res - name: host is rebooting in 15 sec!! ansible.windows.win_reboot: pre_reboot_delay: 15 when: - res.reboot_required | bool - win_base_init__allow_reboot | bool - name: host is rebooting in 15 sec!! ansible.builtin.fail: msg: "Hostname changed. Please reboot to apply changes!" ignore_errors: true when: - res.reboot_required | bool - not win_base_init__allow_reboot | bool