Hi, Ansible devel folks,
This week I put together a module that sets the Splunk Universal Forwarder up on Windows machines. One of the nice things Splunk’s done with the forwarder is make some useful flags that you can pass to msiexec.exe that do things like configure the forwarder as a service, but leave it stopped for now and configured to start on next boot - this is perfect for what I want, which is to set the forwarder set up on a base machine image that I can spin up lots of new instances from and see them automagically start feeding their logs to the indexer.
The whole module in its current state is here - https://gist.github.com/kwerey/e20649d24d8dff63bf39db5ecb569fe1. The goal is to let users do their decision-making in the inventory, in ways that are pretty easy to compare & contrast. So you give it a dictionary of key/value pairs to pass as flags, and the module collapses them into the string you see here called $installParameters. Other than that, it’s not doing anything too complex, just downloading and installing:
`
$cmd = “msiexec.exe /i ${installer_path} RECEIVING_INDEXER=‘${indexer_uri}:${indexer_port}’ ${installParameters} AGREETOLICENSE=yes /quiet” |
|
But… Windows seems to be thwarting my plans. If I stick that variable containing the complete command - $cmd - into the module’s return values, I get this:
`
“cmd”: “msiexec.exe /i C:\Users\vagrant\AppData\Local\Temp\SplunkForwarder.msi RECEIVING_INDEXER=‘192.168.2.10:9997’ LAUNCH_SPLUNK=0 AGREETOLICENSE=yes /quiet”
`
If run that command verbatim in an RDP session, I get exactly the intended behaviour: the forwarder installs, shows up in the results of get-service
as stopped:
`
PS C:\Users\Administrator> msiexec.exe /i C:\Users\vagrant\AppData\Local\Temp\SplunkForwarder.msi RECEIVING_INDEXER='192.168.2.10:9997' LAUNCH_SPLUNK=0 AGREETOLICENSE=yes /quiet
PS C:\Users\Administrator>
PS C:\Users\Administrator> get-service -name Spl*
Status Name DisplayName
------ ---- -----------
Stopped SplunkForwarder SplunkForwarder Service
PS C:\Users\Administrator>
`
But when I run through Ansible, splunkd starts up running. Very mysterious. It’s like it’s not reading the flags, even though it pays attention to /quiet and installs successfully.
I’ve had a google around for how the rules might change when logged in to an RDP session versus running remotely over WinRM, but nothing jumped out at me as suspicious. I thought I was on to something when I realised I’d been running my playbook as the Vagrant user, but RDP’d in as Administrator, but running the Ansible as Administrator doesn’t change anything.
Anyone wise in the ways of Powershell got any tips about where I’m going wrong here?
Thanks,
Nikki