Closed ghost closed 3 years ago
AnsibleRequires -CSharpUtil Ansible.Process was ommited (line: 8)
That's because we are importing the PowerShell util #Requires -Module Ansible.ModuleUtils.CommandUtil
which then has the Ansible.Process
requirement https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/powershell/Ansible.ModuleUtils.CommandUtil.psm1#L4.
Wrong function Get-AnsibleWindowsWebRequestSpec (line: 1295) Whre is no function in Ansible.ModuleUtils.WebRequest with this name, right name is: Get-AnsibleWebRequestSpec
Get-AnsibleWindowsWebRequestSpec
is part of the WebRequest.psm1 module included in the ansible.windows
collection. That's why the import is a relative import #AnsibleRequires -PowerShell ..module_utils.WebRequest
.
The Get-AnsibleWebRequestSpec
function is part of Ansible.ModuleUtils.WebRequest.psm1 which is no longer used by win_package
. It sounds like you might have a mixture of different versions in play, the code as it is today should be fine. We even test it in CI.
Now for the problem at hand, the issue here is that the FusionInventory-Agent
is kicking off a detached process and exiting the main process causing win_package
to think that it has completed and everything is fine. When win_package
exits it also closes the WinRM shell which then kills any remaining child processes that might be running in the background. This is why I believe the module is reporting a change and that it didn't fail but the program doesn't actually get uninstalled.
The fix for this is going to be difficult to debug. I'm trying to see if I can install the package myself and replicate the issue before commenting anymore.
sorry for my english :)
No need to apologise about that, I can only speak 1 language so you are ahead of me in that regard :)
Ok I've been able to replicate the problem, the uninstaller at the registry points to C:\Program Files\FusionInventory-Agent\Uninstall.exe
which win_package
starts. The uninstaller then immediately runs a new executable, which I assume is auto generated, at C:\Users\<username>\AppData\Local\Temp\<random>\Un_A.exe
which does the actual work. Because the original Uninstall.exe
has finished and exited with a return code of 0, win_package
interprets this as everything ran fine and exits normally. When the module finishes, Ansible will close the WinRM shell which then kills any child processes stopping the uninstall from actually continuing in the background.
I found that the -Wait
parameter on Start-Process
has some more advanced logic for checking if any child process has finished than the simple check that win_package
does. I have an idea of how we could also do the same thing but it does have some caveats
win_package
, it uses the return code of the process it creates to determine if things ran fine
win_package
exits
win_package
will hang with no real indication as to why that isThe 2nd scenario may be something I just add as a configurable wait to allow for both scenarios but I will keep you updated as I play around with it some more.
I've got a draft PR that should fix this problem for you. It adds the wait_for_children
option to win_package
and when testing it manually with the installer you mentioned it worked as expected. I still need to add some more test cases for this before it is merged but feel free to try it out when you get a chance.
SUMMARY
In my case im tried to install "FusionInventory agent" after removing of previously installed. For removing i use a win_package module with regedit provider and state absent but it's always returns me "changed: true" and don't uninstall software.
I'm tried to debug scripts (
win_package.ps1
) behavior and got a few guesses about a problem. I think that the root of the problem is in the Ansible.Process.cs. I watched the execution of the task in ansible and through the debug script launched in ISE. In ISE, the execution is successful and the software is removed (in step-by-step mode), but in ansible and ISE in realtime the execution is successful, and the software is not removed. This is due to the fact that the module erroneously returns the result until the moment the software is uninstalled, because uninstall.exe unpack itself inC:\Users\username\AppData\Local\Temp\~nsuA.tmp
and starts a new processUn_A.exe
, andrc: 0
from the terminated uninstall.exe is returned to the task, after which the runspace is closed and the deletion does not continue. Verbose output look like where is 2 exit codes:First from
Uninstall.exe
and second from targetUn_A.exe
My csharp skills is very low and i cant solve the problem after it calls this in
Ansible.ModuleUtils.CommandUtil.psm1
:plz help to fix this little problem.
now I work around the problem using the following set of crutches and it`s works :)
I found some problems in
win_package
module during research:#AnsibleRequires -CSharpUtil Ansible.Process
was ommited (line: 8)before:
after:
Get-AnsibleWindowsWebRequestSpec
(line: 1295) Whre is no function inAnsible.ModuleUtils.WebRequest
with this name, right name is:Get-AnsibleWebRequestSpec
before:
after:
ISSUE TYPE
COMPONENT NAME
win_package Ansible.Process
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
Windows 2019 Std
STEPS TO REPRODUCE
EXPECTED RESULTS
InventoryAgent must be absent
ACTUAL RESULTS
Task works 1sec with "changed: true" but without result.
sorry for my english :)