I have a playbook that simply uses the script module to run a powershell script.
The powershell script merely copies some files then uses “Start-Process” to run a visual studio installer.
When run with ansible, the install does not work. Looking at the visual studio “logs” is not terribly helpful either as it seems every microsoft error is totally ambiguous (in addition to it creating like 10 log files with cryptic names.)
If I just run the script locally, everything works just fine.
How can I debug this further? I was under the impression ansible should just copy the script to the machine and run it using the user I have defined for it to use (which is an admin account and the only one on the machine.)
Where do I go from here?
Usually worth a quick look in the windows event log.
You can also set
export ANSIBLE_KEEP_REMOTE_FILES=1
before running your playbook.
This will keep the generated .ps1 scripts in the users’s temp directory on the windows machine. This is useful as you can then connect to the windows machine and run the same script as ansible does.
I suspect you are hitting an issue where you need to provide a credentials object when running remotely, which explains why the script runs fine when you run on the same machine, but not when you run remotely.
Also, might be worth trying Trond Hindenes’ win_package module as it is intended for running .msi and .exe installers and can pass username and password
https://github.com/ansible/ansible-modules-extras/pull/713
Hope this helps,
Please let us all know how you get on.
Jon
I can’t see anything in the event logs that looks promising.
I’m not too keen on powershell yet.
When you say “run the same script as ansible does” I’m not even sure how I would emulate that.
I tried remoting in and running the script left in the temp directory and it ran just fine, I have a feeling that’s not quite the same process though.
So it sounds very likely that the difference is being caused by ansible running the powershell remotely, rather than locally on the windows machine (where the script runs fine).
You can try adding some lines like the following in to your powershell script to see which line it is failing on.
Echo “my message” | Out-File -FilePath c:\temp\output.txt
Once you have worked out which line is causing it to fail, then I suggest running Get-Help on the command that is failing in powershell.
For example, if it is failing on a line that starts
Invoke-Item
then run
Get-Help Invoke-Item in a powershell windows on your remote windows machine.
Invoke-Item is one of the commands which may need a -Credential object passed to it if, for example, you are using the command to connect to a windows file share.
Some background information here on running remote powershell commands:
https://technet.microsoft.com/en-us/library/dd819505.aspx
and information on Invoke-Item here:
https://technet.microsoft.com/en-us/library/dd347578.aspx
Hope this helps.
Please let us know what you find.
Jon