Ansible win_shell hangs

hi all,

when am trying to execute below ansible command or .bat file it juts hangs at below line can anyone help me on this .

play 1:

  • name: check rdp on windows
    win_shell: ‘mstsc /v:’
    args:
    executable: cmd
    register: result
  • debug:
    var: result

Play 2:

  • name: execute bat file
    win_command: C:\devops\demo.bat

when i execute any above play it just hangs at below output

Output:
TASK [check rdp on windows] *********************************************************************************************************************************** task path: /home/vagrant/ansible/server_control.yml:13 Using module file /usr/lib/python2.7/site-packages/ansible/modules/windows/win_shell.ps1 ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5986 TO checking if winrm_host is an IPv6 address WINRM CONNECT: transport=ssl endpoint=https://:5986/wsman WINRM OPEN SHELL: F40E1253-9543-4A6D-A791-D747BDC7B7D6 EXEC (via pipeline wrapper) WINRM EXEC ‘PowerShell’ [‘-NoProfile’, ‘-NonInteractive’, ‘-ExecutionPolicy’, ‘Unrestricted’, ‘-’] (It just hang here)

Running a command through Ansible is not designed to run interactive programs. Everything is run in the background with no interactive Window and will wait until the process has exited. Because running mstsc is a GUI application, it will stay open forever which results in win_shell/win_command waiting forever for it to quit which will never occur as no one can see the Window. There are ways to run things in the background asynchronously but in this case there is no reason as opening a GUI application from Ansible will not display it on any interactive desktop.

hi jordan,

thanks for your reply can you please tell us how this can be achieved through other programming or automation.