I have some vendor software where I am trying to uninstall (following their procedure) by obtaining the uninstall command and install location from the windows registry. I do this by querying win_reg_stat and storing result in two facts. I am then trying to execute the variable via win_shell and win_command in various guises but with no success. Even stripping it back to the bare uninstall command with no parameters is proving difficult eg
We would probably need some more information and not just a blank variable called uninstall. You can omit names but keep the structure and arguments the same so we can see what exactly is the value from the registry key. Are you also able to share the registry path you are querying as you might be able to use win_package for this instead.
It fails to run it with “unable to exec C:\Program.exe” - ie the single quote i had around the “{{uninstall}” previously have moved around the entire command, but it now has issue with whitepsace in {{ uninstall }} variable path.
If I put the single qoute back around the {{uninstall}} with parameters after…
Appears the vendor is not storing productID in the expected path
ON a different tact to avoid the extra single quoting on the executable, I tried obtaining the windows short path for the file. win_stat does not provide it. So I ran a successful win_shell cmd as follows:
win_shell: cmd /c for %A in ("{{ uninstall }}") do @echo %~sA
args:
executable: cmd
…however in the stdout it is not returning the shorthand version like when I do it manually on a dos prompt
You can pass win_shell a chdir in the ‘args’ section as well if that helps (may not if a full path is needed).
Feel free to go back to your vendor and ask them how their automated testing works if its such a pain to install/uninstall their product. The only way we will get better quality installers is if vendors get badgered into making them.
While you can use win_shell I find it is better to use win_command when it comes to running executables, this way you don’t fall prey to the shell specific escaping, e.g. when using win_shell you usually have to do it like;
win_shell: &“C:\Program Files\someapp\app.exe”
compared to
win_command: ‘“C:\Program Files\someapp\app.exe”’
This is because win_shell will automatically run the param in PowerShell as an encoded command and when a quoted value is run in powershell it will just print it to the screen, the & tells it to execute it. You read more about this here http://docs.ansible.com/ansible/devel/windows_usage.html#running-commands.
For your specific situation I would try (note you would need some sort of when clause to skip this task if it is already uninstalled);
name: uninstall application
win_command: ‘“C:\Program Files (x86)\My Software\It Is Mine\myagent\uninstall.exe” /S “_?=C:\Program Files (x86)\My Software\It Is Mine\myagent”’
In this example, I have
put the entire win_command value inside single quotes that tells the Ansible yml parser this is all one value and ignore things like double quotes, backslashes and other escaping chars
used double quotes to enclose the first argument which is the path to the executable as well as the 3rd argument which also has spaces in it
I didn’t use jinja2 blocks but if you need to substitute the path, leave the quoting as is as it is very important they stay like that, e.g. make it like
argv[0] = C:\Program Files (x86)\My Software\It Is Mine\myagent\uninstall.exe
argv[1] = /S
argv[2] = _?=C:\Program Files (x86)\My Software\It Is Mine\myagent
Where argv[0] is the path to the executable that is used to start the process. This follows Microsoft standard rules for argument parsing and in the application entry point, the argv array above is what will be passed in so it should work. Hopefully this helps you with what you need to do.