Ansible hangs on Windows cleanmgr.exe

1,002 views
Skip to first unread message

SurferL

unread,
Aug 22, 2018, 8:43:24 AM8/22/18
to Ansible Project
Using Ansible 2.6.2, I've set `cleanmgr.exe /sagerun:3` to everything possible manually on the Windows 10 machine.

In my playbook I have the following task:

- name: windows | disk cleanup
win_shell: "cmd.exe /c cleanmgr.exe /sagerun:3"
args:
chdir: "C:\\Windows\\system32"

However it hangs on this task it seems, and I can't seem to figure out why, or what I could be debugging. 

Running the command manually on the machine locally works fine. Also, the command works fine for Windows 7 machine, so I'm not sure this could be a configuration issue on the Windows 10 machine?

Ansible debug (showing the ping task just before it hangs):

TASK [cleanup : windows | verify connection] ***********************************
task path: /Users/ansible/builds/0/clean_base_vms/ansible/roles/cleanup/tasks/windows.yml:3
ok: [win10_base] => {
"changed": false,
"ping": "pong"
}
Using module file /Users/ansible/clean_base_vms/virtualenv/lib/python2.7/site-packages/ansible/modules/windows/win_shell.ps1
<ip-address> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5985 TO <ip-address>
checking if winrm_host <ip-address> is an IPv6 address
<ip-address> WINRM CONNECT: transport=plaintext endpoint=http://<ip-address>:5985/wsman
<ip-address> WINRM OPEN SHELL: <shell-thing>
EXEC (via pipeline wrapper)
<ip-address> WINRM EXEC 'PowerShell' ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Unrestricted', '-']


I've left this task running for 5 hours before it fails...

Any ideas would be greatly appreciated, thank you in advance :) 

J Hawkesworth

unread,
Sep 4, 2018, 5:36:11 AM9/4/18
to Ansible Project
cleanmgr is probably waiting for window to display progress, but winrm has no window available so that's probably why it hangs


You might be able to use something like this, but I haven't tried it myself 

Start-Process -FilePath CleanMgr.exe -ArgumentList '/sagerun:1' -WindowStyle Hidden -Wait

or perhaps

Start-Process -FilePath CleanMgr.exe -ArgumentList '/sagerun:1' -NoNewWindow -Wait

SurferL

unread,
Sep 4, 2018, 5:41:47 AM9/4/18
to Ansible Project
Thanks for the response - I'll give this a test!

One thing I did find weird was that I left the job running overnight, and it succeeded in about 20 hours... so not sure what's happening there. (When running manually it takes ~5 minutes).

Jordan Borean

unread,
Sep 4, 2018, 4:37:23 PM9/4/18
to Ansible Project
cleanmgr.exe is an annoying one to run in a non-interactive process. Unless you get it just right it will run and just wait for user input which won't happen as there's no UI. I've been able to get it working which you can see at https://github.com/jborean93/packer-windoze/blob/master/roles/cleanup-winsxs/tasks/cleanmgr.yml#L61-L79. The state flag number isn't important, was just a number I chose to have a bit of fun but it can be anything as long as they match each other.

Thanks

Jordan
Reply all
Reply to author
Forward
0 new messages