# trying to debug ansible and win\_package

**URL:** <https://forum.ansible.com/t/trying-to-debug-ansible-and-win-package/38650>\
**Category:** Ansible Project\
**Tags:** windows, ansible-lint\
**Created:** [January 12, 2024, 4:43pm UTC](https://forum.ansible.com/t/trying-to-debug-ansible-and-win-package/38650 "2024-01-12T16:43:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Divan\_Santana](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@Divan\_Santana](https://forum.ansible.com/u/Divan_Santana)\
**Post date:** [January 12, 2024, 4:43pm UTC](https://forum.ansible.com/t/trying-to-debug-ansible-and-win-package/38650/1 "2024-01-12T16:43:22Z")

</div>

Hi,

I'm trying to debug a ansible windows issue, if someone with powershell  
knowledge could help me debug it, it would be great.

I can successfully win\_ping win\_setup the windows 2019SE server, but not  
win\_package install or install using chocolatey. No idea why.

I have this piece of ansible code, to install a package via win\_package.

&nbsp;&nbsp;- name: Ensure 7-Zip is installed through win\_package  
&nbsp;&nbsp;&nbsp;&nbsp;win\_package:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path: C:\temp\7z.exe  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: present

The above fails with:

&nbsp;&nbsp;The win\_package action failed to execute in the expected time frame (5) and was terminated.

I run my playbook with -vvvvv, I see this[1] in the output. I believe  
to debug this further I need to run the powershell script on the windows  
box directly. I'm not quite sure how to do that. What I've done is  
enable powershell script block logging, so that I can decode the  
EncodedCommand string (not sure how else to decode it?). Looking at the  
Event Viewer, I can see that the powershell script block is this[2].

I'm rather clueless with powershell. I'm now stuck at, how can I  
execute this powershell script block[2] in the same manner as ansible is  
doing it, to see why it's failing to install? Currently I take the  
scriptblock[2] as is and paste it in powershell which simply returns  
nothing to the screen.

Any help would be appreciated. Version details in [3].

[1]:  
Using module file /home/opc/.ansible/collections/ansible\_collections/ansible/windows/plugins/modules/win\_package.ps1  
Pipelining is enabled.  
\<10.20.100.184\> ESTABLISH WINRM CONNECTION FOR USER: opc on PORT 5986 TO 10.20.100.184  
\<10.20.100.184\> WINRM CONNECT: transport=credssp endpoint=[https://10.20.100.184:5986/wsman](https://10.20.100.184:5986/wsman)  
\<10.20.100.184\> WINRM OPEN SHELL: 37E74DAA-A27C-4642-89BB-CDDD11AF95DF  
EXEC (via pipeline wrapper)  
\<10.20.100.184\> WINRM EXEC 'PowerShell' ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Unrestricted', '-EncodedCommand', 'UABvAHcAZQByAFMAaABlAGwAbAAgAC0ATgBvAFAAcgBvAGYAaQBsAGUAIAAtAE4AbwBuAEkAbgB0AGUAcgBhAGMAdABpAHYAZQAgAC0ARQB4AGUAYwB1AHQAaQBvAG4AUABvAGwAaQBjAHkAIABVAG4AcgBlAHMAdAByAGkAYwB0AGUAZAAgAC0ARQBuAGMAbwBkAGUAZABDAG8AbQBtAGEAbgBkACAASgBnAEIAagBBAEcAZwBBAFkAdwBCAHcAQQBDADQAQQBZAHcAQgB2AEEARwAwAEEASQBBAEEAMgBBAEQAVQBBAE0AQQBBAHcAQQBEAEUAQQBJAEEAQQArAEEAQwBBAEEASgBBAEIAdQBBAEgAVQBBAGIAQQBCAHMAQQBBAG8AQQBhAFEAQgBtAEEAQwBBAEEASwBBAEEAawBBAEYAQQBBAFUAdwBCAFcAQQBHAFUAQQBjAGcAQgB6AEEARwBrAEEAYgB3AEIAdQBBAEYAUQBBAFkAUQBCAGkAQQBHAHcAQQBaAFEAQQB1AEEARgBBAEEAVQB3AEIAVwBBAEcAVQBBAGMAZwBCAHoAQQBHAGsAQQBiAHcAQgB1AEEAQwBBAEEATABRAEIAcwBBAEgAUQBBAEkAQQBCAGIAQQBGAFkAQQBaAFEAQgB5AEEASABNAEEAYQBRAEIAdgBBAEcANABBAFgAUQBBAGkAQQBEAE0AQQBMAGcAQQB3AEEAQwBJAEEASwBRAEEAZwBBAEgAcwBBAEMAZwBBAG4AQQBIAHMAQQBJAG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YgBnAEIAZgBBAEgASQBBAFkAUQBCADMAQQBDAEEAQQBMAFEAQgBXAEEARwBFAEEAYgBBAEIAMQBBAEcAVQBBAEkAQQBBAGsAQQBIAE0AQQBjAEEAQgBzAEEARwBrAEEAZABBAEIAZgBBAEgAQQBBAFkAUQBCAHkAQQBIAFEAQQBjAHcAQgBiAEEARABFAEEAWABRAEEASwBBAEMAUQBBAFoAUQBCADQAQQBHAFUAQQBZAHcAQgBmAEEASABjAEEAYwBnAEIAaABBAEgAQQBBAGMAQQBCAGwAQQBIAEkAQQBJAEEAQQA5AEEAQwBBAEEAVwB3AEIAVABBAEcATQBBAGMAZwBCAHAAQQBIAEEAQQBkAEEAQgBDAEEARwB3AEEAYgB3AEIAagBBAEcAcwBBAFgAUQBBADYAQQBEAG8AQQBRAHcAQgB5AEEARwBVAEEAWQBRAEIAMABBAEcAVQBBAEsAQQBBAGsAQQBIAE0AQQBjAEEAQgBzAEEARwBrAEEAZABBAEIAZgBBAEgAQQBBAFkAUQBCAHkAQQBIAFEAQQBjAHcAQgBiAEEARABBAEEAWABRAEEAcABBAEEAbwBBAEoAZwBBAGsAQQBHAFUAQQBlAEEAQgBsAEEARwBNAEEAWAB3AEIAMwBBAEgASQBBAFkAUQBCAHcAQQBIAEEAQQBaAFEAQgB5AEEAQQA9AD0A']  
\<10.20.100.184\> WINRM CLOSE SHELL: 37E74DAA-A27C-4642-89BB-CDDD11AF95DF  
fatal: [divan-windows-test-prod]: FAILED! =\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"changed": false,  
&nbsp;&nbsp;&nbsp;&nbsp;"msg": "The win\_package action failed to execute in the expected time frame (5) and was terminated"  
}

[2]:

{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;param (  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WaitChildren = $WaitChildren  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($Path) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$invokeParams.CommandLine = ConvertTo-EscapedArgument -InputObject $Path  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$registryProperties = Get-ItemProperty -LiteralPath $RegistryPath

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ('QuietUninstallString' -in $registryProperties.PSObject.Properties.Name) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$command = $registryProperties.QuietUninstallString  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elseif ('UninstallString' -in $registryProperties.PSObject.Properties.Name) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$command = $registryProperties.UninstallString  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$module.FailJson("Failed to find registry uninstall string at registry path '$RegistryPath'")  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# If the uninstall string starts with '%', we need to expand the env vars.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($command.StartsWith('%') -or $command.StartsWith('"%')) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$command = [System.Environment]::ExpandEnvironmentVariables($command)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# If the command is not quoted and contains spaces we need to see if it needs to be manually quoted for the executable.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (-not $command.StartsWith('"') -and $command.Contains(' ')) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$rawArguments = [System.Collections.Generic.List[String]]@()

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$executable = New-Object -TypeName System.Text.StringBuilder  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach ($cmd in ($command | ConvertFrom-EscapedArgument)) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($rawArguments.Count -eq 0) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Still haven't found the path, append the arg to the executable path and see if it exists.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$null = $executable.Append($cmd)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$exe = $executable.ToString()  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (Test-Path -LiteralPath $exe -PathType Leaf) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$rawArguments.Add($ex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p;&nbsp;else {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$rawArguments.Add($cmd)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# If we still couldn't find a file just use the command literally and hope WIndows can handle it,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# otherwise recombine the args which will also quote whatever is needed.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($rawArguments.Count -gt 0) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$command = @($rawArguments | ConvertTo-EscapedArgument) -join ' '  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$invokeParams.CommandLine = $command  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($Arguments) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$invokeParams.CommandLine += " $Arguments"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Invoke-Executable @invokeParams  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

My version details are[3]:

[3]:  
ansible 2.16  
python 3.10.13  
ansible.windows 2.1.0

pip list:

ansible 9.0.1  
ansible-compat 4.1.10  
ansible-core 2.16.0  
ansible-lint 6.22.0  
arrow 1.3.0  
attrs 23.1.0  
black 23.11.0  
bracex 2.4  
certifi 2023.11.17  
cffi 1.16.0  
charset-normalizer 3.3.2  
circuitbreaker 1.4.0  
click 8.0.4  
cryptography 41.0.5  
decorator 5.1.1  
filelock 3.13.1  
gssapi 1.8.3  
idna 3.4  
Jinja2 3.1.2  
jmespath 0.10.0  
jsonschema 4.20.0  
jsonschema-specifications 2023.11.1  
krb5 0.5.1  
markdown-it-py 3.0.0  
MarkupSafe 2.1.3  
mdurl 0.1.2  
mypy-extensions 1.0.0  
oci 2.116.0  
oci-cli 3.36.2  
packaging 23.2  
pathspec 0.11.2  
pip 23.0.1  
platformdirs 4.0.0  
prompt-toolkit 3.0.29  
pycparser 2.21  
Pygments 2.17.2  
pykerberos 1.2.4  
pyOpenSSL 23.3.0  
pyspnego 0.10.2  
python-dateutil 2.8.2  
pytz 2023.3.post1  
pywinrm 0.4.3  
PyYAML 6.0.1  
referencing 0.31.0  
requests 2.31.0  
requests-credssp 2.0.0  
requests-kerberos 0.14.0  
requests-ntlm 1.2.0  
resolvelib 1.0.1  
rich 13.7.0  
rpds-py 0.13.1  
ruamel.yaml 0.18.5  
ruamel.yaml.clib 0.2.8  
setuptools 65.5.0  
six 1.16.0  
subprocess-tee 0.4.1  
terminaltables 3.1.0  
tomli 2.0.1  
types-python-dateutil 2.8.19.14  
typing\_extensions 4.8.0  
urllib3 2.1.0  
wcmatch 8.5  
wcwidth 0.2.12  
xmltodict 0.13.0  
yamllint 1.33.0

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [January 12, 2024, 10:06pm UTC](https://forum.ansible.com/t/trying-to-debug-ansible-and-win-package/38650/2 "2024-01-12T22:06:44Z")

</div>

The only time this error ever appears is if you have a timeout set on the task [1]. Check to ensure you don’t have that config entry set ‘ansible-config dump --only-changed’ or haven’t set it on the task play.

[1] [https://docs.ansible.com/ansible/latest/reference\_appendices/config.html#task-timeout](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#task-timeout)

---

<div class="post-metadata">

**Author:** ![Divan\_Santana](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@Divan\_Santana](https://forum.ansible.com/u/Divan_Santana)\
**Post date:** [January 15, 2024, 8:26am UTC](https://forum.ansible.com/t/trying-to-debug-ansible-and-win-package/38650/3 "2024-01-15T08:26:57Z")

</div>

> > The win\_package action failed to execute in the expected time frame (5)  
> > and was terminated.

> The only time this error ever appears is if you have a timeout set on the  
> task [1]. Check to ensure you don't have that config entry set  
> 'ansible-config dump --only-changed' or haven't set it on the task play.
> 
> [1]  
> [https://docs.ansible.com/ansible/latest/reference\_appendices/config.html#task-timeout](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#task-timeout)

No it's not that sadly. It times out before 5 seconds anyway.

Checking ansible-config dump --only-changed it says:

ANSIBLE\_NOCOWS(/home/opc/vb-ansible-core/ansible.cfg) = True  
CALLBACKS\_ENABLED(/home/opc/vb-ansible-core/ansible.cfg) = ['ansible.posix.profile\_tasks']  
CONFIG\_FILE() = /home/opc/vb-ansible-core/ansible.cfg  
DEFAULT\_BECOME(/home/opc/vb-ansible-core/ansible.cfg) = False  
DEFAULT\_FORKS(/home/opc/vb-ansible-core/ansible.cfg) = 100  
DEFAULT\_HOST\_LIST(/home/opc/vb-ansible-core/ansible.cfg) = ['/home/opc/vb-ansible-core/inventories/auto\_inventory.oci.yml', '/home/opc/vb-ansible-core/invent\>  
DEFAULT\_LOG\_PATH(/home/opc/vb-ansible-core/ansible.cfg) = /home/opc/vb-ansible-core/.logs/ansible.log  
DEFAULT\_ROLES\_PATH(/home/opc/vb-ansible-core/ansible.cfg) = ['/home/opc/vb-ansible-core/roles\_external', '/home/opc/vb-ansible-core/roles']  
DEFAULT\_TIMEOUT(/home/opc/vb-ansible-core/ansible.cfg) = 30  
HOST\_KEY\_CHECKING(/home/opc/vb-ansible-core/ansible.cfg) = False  
INTERPRETER\_PYTHON(/home/opc/vb-ansible-core/ansible.cfg) = auto\_silent  
RETRY\_FILES\_ENABLED(/home/opc/vb-ansible-core/ansible.cfg) = True  
RETRY\_FILES\_SAVE\_PATH(/home/opc/vb-ansible-core/ansible.cfg) = /home/opc/.ansible-retry

Moreover explicitly setting task\_timeout = 60 or 0 in ansible.cfg, results in the  
same error.

---

<div class="post-metadata">

**Author:** ![Divan\_Santana](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@Divan\_Santana](https://forum.ansible.com/u/Divan_Santana)\
**Post date:** [January 15, 2024, 9:07am UTC](https://forum.ansible.com/t/trying-to-debug-ansible-and-win-package/38650/4 "2024-01-15T09:07:58Z")

</div>

> I'm rather clueless with powershell. I'm now stuck at, how can I  
> execute this powershell script block[2] in the same manner as ansible is  
> doing it, to see why it's failing to install? Currently I take the  
> scriptblock[2] as is and paste it in powershell which simply returns  
> nothing to the screen.

OK, I think I run the powershell script like so via cmd:

powershell -NoProfile -NonInteractive -ExecutionPolicy Unrestricted Invoke-Command -ScriptBlock { param ( [String] $Arguments, [Int32] $ReturnCodes, [Object] $Module, [String] $Path, [String] $State, [String] $WorkingDirectory, [String] $RegistryPath, [Switch] $WaitChildren ) $invokeParams = @{ Module = $Module ReturnCodes = $ReturnCodes WorkingDirectory = $WorkingDirectory WaitChildren = $WaitChildren } if ($Path) { $invokeParams.CommandLine = ConvertTo-EscapedArgument -InputObject $Path } else { $registryProperties = Get-ItemProperty -LiteralPath $RegistryPath if ('QuietUninstallString' -in $registryProperties.PSObject.Properties.Name) { $command = $registryProperties.QuietUninstallString } elseif ('UninstallString' -in $registryProperties.PSObject.Properties.Name) { $command = $registryProperties.UninstallString } else { $module.FailJson("Failed to find registry uninstall string at registry path '$RegistryPath'") } # If the uninstall string starts with '%', we need to expand the env vars. if ($command.StartsWith('%') -or $command.StartsWith('"%')) { $command = [System.Environment]::ExpandEnvironmentVariables($command) } # If the command is not quoted and contains spaces we need to see if it needs to be manually quoted for the executable. if (-not $command.StartsWith('"') -and $command.Contains(' ')) { $rawArguments = [System.Collections.Generic.List[String]]@() $executable = New-Object -TypeName System.Text.StringBuilder foreach ($cmd in ($command | ConvertFrom-EscapedArgument)) { if ($rawArguments.Count -eq 0) { # Still haven't found the path, append the arg to the executable path and see if it exists. $null = $executable.Append($cmd) $exe = $executable.ToString() if (Test-Path -LiteralPath $exe -PathType Leaf) { $rawArguments.Add($exe) } else { $null = $executable.Append(" ") # The arg had a space and we need to preserve that. } } else { $rawArguments.Add($cmd) } } # If we still couldn't find a file just use the command literally and hope WIndows can handle it, # otherwise recombine the args which will also quote whatever is needed. if ($rawArguments.Count -gt 0) { $command = @($rawArguments | ConvertTo-EscapedArgument) -join ' ' } } $invokeParams.CommandLine = $command } if ($Arguments) { $invokeParams.CommandLine += " $Arguments" } Invoke-Executable @invokeParams }

That results in this error:

'ConvertFrom-EscapedArgument))' is not recognized as an internal or external command, operable program or batch file.

Anyone have a clue what's wrong?

My Powershell version is:

&nbsp;&nbsp;Name Value  
&nbsp;&nbsp;---- -----  
&nbsp;&nbsp;PSVersion 5.1.17763.5328  
&nbsp;&nbsp;PSEdition Desktop  
&nbsp;&nbsp;PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}  
&nbsp;&nbsp;BuildVersion 10.0.17763.5328  
&nbsp;&nbsp;CLRVersion 4.0.30319.42000  
&nbsp;&nbsp;WSManStackVersion 3.0  
&nbsp;&nbsp;PSRemotingProtocolVersion 2.3  
&nbsp;&nbsp;SerializationVersion 1.1.0.1

.net version is:

&nbsp;&nbsp;Release in one case says =0x00080eb1=  
&nbsp;&nbsp;InstallPath =C:\Windows\Microsoft.Net\Framework64\v4.0.30319=  
&nbsp;&nbsp;Version =4.8.03761=

---

<div class="post-metadata">

**Author:** ![Divan\_Santana](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@Divan\_Santana](https://forum.ansible.com/u/Divan_Santana)\
**Post date:** [January 26, 2024, 9:09am UTC](https://forum.ansible.com/t/trying-to-debug-ansible-and-win-package/38650/5 "2024-01-26T09:09:42Z")

</div>

> The above fails with:
> 
> &nbsp;&nbsp;The win\_package action failed to execute in the expected time frame (5) and was terminated.

OK, I was being stupid. There was a timeout: 5 at the top of my play.

win\_package now hangs while trying to install. I've disabled UAC, but  
still it just hangs.

---

<div class="post-metadata">

**Author:** ![Divan\_Santana](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@Divan\_Santana](https://forum.ansible.com/u/Divan_Santana)\
**Post date:** [January 27, 2024, 12:34pm UTC](https://forum.ansible.com/t/trying-to-debug-ansible-and-win-package/38650/6 "2024-01-27T12:34:06Z")

</div>

Divan Santana \<divan@santanas.co.za\> writes:

> > The above fails with:
> > 
> > &nbsp;&nbsp;The win\_package action failed to execute in the expected time frame (5) and was terminated.
> 
> OK, I was being stupid. There was a timeout: 5 at the top of my play.
> 
> win\_package now hangs while trying to install. I've disabled UAC, but  
> still it just hangs.

OK, the win\_package install works fine too. Seems one needs to look at  
the exe maker and figure out which switch to use for a silent install.
