--- - name: check if powershell is available raw: 'Get-Host' failed_when: False check_mode: no register: check_powershell - block: - name: enable powershell raw: '{{ item }}' args: executable: cmd.exe changed_when: False check_mode: no loop: - dism /online /enable-feature /featurename:NetFx2-ServerCore - dism /online /enable-feature /featurename:MicrosoftWindowsPowerShell - dism /online /enable-feature /featurename:ServerManager-PSH-Cmdlets - name: reboot system raw: shutdown /r /t 5 args: executable: cmd.exe changed_when: False check_mode: no - pause: seconds: 30 when: - check_powershell.stderr is defined - ('is not recognized' in check_powershell.stderr)