--- - name: "Change the hostname to {{ inventory_hostname }}" ansible.windows.win_hostname: name: "{{ inventory_hostname }}" register: res - name: Reboot ansible.windows.win_reboot: when: res.reboot_required