Ansible win_shell hangs

61 views
Skip to first unread message

Bairava Surya

unread,
Nov 27, 2019, 4:52:37 AM11/27/19
to Ansible Project
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:<windows hostname or IP>'
      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 <windows hostname or IP> ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5986 TO <windows hostname or IP> checking if winrm_host <windows hostname or IP> is an IPv6 address <windows hostname or IP> WINRM CONNECT: transport=ssl endpoint=https://<windows hostname or IP>:5986/wsman <windows hostname or IP> WINRM OPEN SHELL: F40E1253-9543-4A6D-A791-D747BDC7B7D6 EXEC (via pipeline wrapper) <windows hostname or IP> WINRM EXEC 'PowerShell' ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Unrestricted', '-'] (It just hang here)





Jordan Borean

unread,
Dec 1, 2019, 3:52:54 PM12/1/19
to Ansible Project
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.

Bairava Surya

unread,
Dec 1, 2019, 10:20:57 PM12/1/19
to Ansible Project
hi jordan,

thanks for your reply can you please tell us how this can be achieved through other programming or automation. 
Reply all
Reply to author
Forward
0 new messages