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

- win_command: '"{{ uninstall_path }}" /S "_?={{ unisntall_path }}"'

In the end Windows will see this as

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.

Thanks

Jordan

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1bd599f5-967e-462b-8d09-d19f6ec328b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to