Any support for template in Windows?

Hi there, somewhat new to Ansible, just using it for the past year on Linux hosts. I’m working on a project that has me applying ansible to a windows deployment scenario and I find myself in need of the template capability to push customized configuration files to my windows hosts. Is there some way to achieve this right now in the devel branch? On a lark I tried this in my script and was rewarded with the following output:

TASK: [xxx/yyyyyy | Personalize the wptdriver.ini file for the instance] ***
<192.168.56.102> ESTABLISH WINRM CONNECTION FOR USER: vagrant on PORT 5986 TO 192.168.56.102
<192.168.56.102> WINRM REUSE EXISTING CONNECTION: vagrant:63623900c8bbf21c706c45dcb7a2c083@192.168.56.102:5986
<192.168.56.102> EXEC (New-Item -Type Directory -Path $env:temp -Name “ansible-tmp-1410996840.36-253897514095560”).FullName | Write-Host -Separator ‘’;
<192.168.56.102> WINRM EXEC ‘PowerShell’ [‘-NoProfile’, ‘-NonInteractive’, ‘-EncodedCommand’, ‘KABOAGUAdwAtAEkAdABlAG0AIAAtAFQAeQBwAGUAIABEAGkAcgBlAGMAdABvAHIAeQAgAC0AUABhAHQAaAAgACQAZQBuAHYAOgB0AGUAbQBwACAALQBOAGEAbQBlACAAIgBhAG4AcwBpAGIAbABlAC0AdABtAHAALQAxADQAMQAwADkAOQA2ADgANAAwAC4AMwA2AC0AMgA1ADMAOAA5ADcANQAxADQAMAA5ADUANQA2ADAAIgApAC4ARgB1AGwAbABOAGEAbQBlACAAfAAgAFcAcgBpAHQAZQAtAEgAbwBzAHQAIAAtAFMAZQBwAGEAcgBhAHQAbwByACAAJwAnADsA’]
<192.168.56.102> WINRM RESULT <Response code 0, out “C:\Users\vagrant\App”, err “”>
<192.168.56.102> EXEC If (Test-Path -PathType Leaf “C:\webpagetest\wptdriver.ini”) { $sp = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider; $fp = [System.IO.File]::Open(“C:\webpagetest\wptdriver.ini”, [System.IO.Filemode]::Open, [System.IO.FileAccess]::Read); [System.BitConverter]::ToString($sp.ComputeHash($fp)).Replace(“-”, “”).ToLower(); $fp.Dispose(); } ElseIf (Test-Path -PathType Container “C:\webpagetest\wptdriver.ini”) { Write-Host “3”; } Else { Write-Host “1”; }
<192.168.56.102> WINRM EXEC ‘PowerShell’ [‘-NoProfile’, ‘-NonInteractive’, ‘-EncodedCommand’, ‘SQBmACAAKABUAGUAcwB0AC0AUABhAHQAaAAgAC0AUABhAHQAaABUAHkAcABlACAATABlAGEAZgAgACIAQwA6AFwAdwBlAGIAcABhAGcAZQB0AGUAcwB0AFwAdwBwAHQAZAByAGkAdgBlAHIALgBpAG4AaQAiACkACgB7AAoAJABzAHAAIAA9ACAAbgBlAHcALQBvAGIAagBlAGMAdAAgAC0AVAB5AHAAZQBOAGEAbQBlACAAUwB5AHMAdABlAG0ALgBTAGUAYwB1AHIAaQB0AHkALgBDAHIAeQBwAHQAbwBnAHIAYQBwAGgAeQAuAE0ARAA1AEMAcgB5AHAAdABvAFMAZQByAHYAaQBjAGUAUAByAG8AdgBpAGQAZQByADsACgAkAGYAcAAgAD0AIABbAFMAeQBzAHQAZQBtAC4ASQBPAC4ARgBpAGwAZQBdADoAOgBPAHAAZQBuACgAIgBDADoAXAB3AGUAYgBwAGEAZwBlAHQAZQBzAHQAXAB3AHAAdABkAHIAaQB2AGUAcgAuAGkAbgBpACIALAAgAFsAUwB5AHMAdABlAG0ALgBJAE8ALgBGAGkAbABlAG0AbwBkAGUAXQA6ADoATwBwAGUAbgAsACAAWwBTAHkAcwB0AGUAbQAuAEkATwAuAEYAaQBsAGUAQQBjAGMAZQBzAHMAXQA6ADoAUgBlAGEAZAApADsACgBbAFMAeQBzAHQAZQBtAC4AQgBpAHQAQwBvAG4AdgBlAHIAdABlAHIAXQA6ADoAVABvAFMAdAByAGkAbgBnACgAJABzAHAALgBDAG8AbQBwAHUAdABlAEgAYQBzAGgAKAAkAGYAcAApACkALgBSAGUAcABsAGEAYwBlACgAIgAtACIALAAgACIAIgApAC4AVABvAEwAbwB3AGUAcgAoACkAOwAKACQAZgBwAC4ARABpAHMAcABvAHMAZQAoACkAOwAKAH0ACgBFAGwAcwBlAEkAZgAgACgAVABlAHMAdAAtAFAAYQB0AGgAIAAtAFAAYQB0AGgAVAB5AHAAZQAgAEMAbwBuAHQAYQBpAG4AZQByACAAIgBDADoAXAB3AGUAYgBwAGEAZwBlAHQAZQBzAHQAXAB3AHAAdABkAHIAaQB2AGUAcgAuAGkAbgBpACIAKQAKAHsACgBXAHIAaQB0AGUALQBIAG8AcwB0ACAAIgAzACIAOwAKAH0ACgBFAGwAcwBlAAoAewAKAFcAcgBpAHQAZQAtAEgAbwBzAHQAIAAiADEAIgA7AAoAfQA=’]
<192.168.56.102> WINRM RESULT <Response code 0, out "1 ", err “”>
<192.168.56.102> PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIhJRqZ TO C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\source
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIhJRqZ to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\source (offset=0 size=736)
<192.168.56.102> PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d TO C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=0 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=2037 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=4074 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=6111 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=8148 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=10185 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=12222 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=14259 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=16296 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=18333 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=20370 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=22407 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=24444 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=26481 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=28518 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=30555 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=32592 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=34629 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=36666 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=38703 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=40740 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=42777 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=44814 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=46851 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=48888 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=50925 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=52962 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=54999 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=57036 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=59073 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=61110 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=63147 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=65184 size=2037)
<192.168.56.102> WINRM PUT /var/folders/jb/1hrps5cs6ygggc41yly4pzpr5c632v/T/tmpIgJx1d to C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy (offset=67221 size=777)
<192.168.56.102> EXEC PowerShell -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -File “C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy.ps1”; Remove-Item "C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560" -Force -Recurse;
<192.168.56.102> WINRM EXEC ‘PowerShell’ [‘-NoProfile’, ‘-NonInteractive’, ‘-EncodedCommand’, ‘UABvAHcAZQByAFMAaABlAGwAbAAgAC0ATgBvAFAAcgBvAGYAaQBsAGUAIAAtAE4AbwBuAEkAbgB0AGUAcgBhAGMAdABpAHYAZQAgAC0ARQB4AGUAYwB1AHQAaQBvAG4AUABvAGwAaQBjAHkAIABVAG4AcgBlAHMAdAByAGkAYwB0AGUAZAAgAC0ARgBpAGwAZQAgACIAQwA6AFwAVQBzAGUAcgBzAFwAdgBhAGcAcgBhAG4AdABcAEEAcABwAEQAYQB0AGEAXABMAG8AYwBhAGwAXABUAGUAbQBwAFwAYQBuAHMAaQBiAGwAZQAtAHQAbQBwAC0AMQA0ADEAMAA5ADkANgA4ADQAMAAuADMANgAtADIANQAzADgAOQA3ADUAMQA0ADAAOQA1ADUANgAwAFwAXABjAG8AcAB5AC4AcABzADEAIgA7ACAAUgBlAG0AbwB2AGUALQBJAHQAZQBtACAAIgBDADoAXABVAHMAZQByAHMAXAB2AGEAZwByAGEAbgB0AFwAQQBwAHAARABhAHQAYQBcAEwAbwBjAGEAbABcAFQAZQBtAHAAXABhAG4AcwBpAGIAbABlAC0AdABtAHAALQAxADQAMQAwADkAOQA2ADgANAAwAC4AMwA2AC0AMgA1ADMAOAA5ADcANQAxADQAMAA5ADUANQA2ADAAXAAiACAALQBGAG8AcgBjAGUAIAAtAFIAZQBjAHUAcgBzAGUAOwA=’]
<192.168.56.102> WINRM RESULT <Response code 0, out “”, err “The argument 'C:\Use”>
failed: [192.168.56.102] => {“failed”: true, “parsed”: false}
The argument ‘C:\Users\vagrant\AppData\Local\Temp\ansible-tmp-1410996840.36-253897514095560\copy.ps1’ to the -File parameter does not exist. Provide the path to an existing ‘.ps1’ file as an argument to the -File parameter.

If there is a way to achieve this I would be interested to know. Thanks!

The template module depends on the copy and file modules, so it should just
work once we have working Powershell implementations of the copy and file
modules. So, not yet.

https://github.com/ansible/ansible/pull/8241 is the only pull request so
far for a win_copy module, but we'll probably go with something that
doesn't depend on pysmbc by default.

https://github.com/ansible/ansible/pull/8876 is the only pull request so
far for a win_file module, and I haven't yet had a chance to test it.

Thanks for the reply, by any chance is there anything like a rough roadmap/timeline for the Windows stuff? I realize its early times and all for the feature but it’d be nice to have some idea of what the plan is.

Technically no.

By 1.8 all ansible modules for windows will be officially supported, what what modules we have is somewhat driven by community inputs.

We’re working on some priority modules for specific use cases though, and that’s not to say this couldn’t be one of those things, but we haven’t specifically said, what Windows things will be in 1.8.

Kerberos/AD auth is likely, as are attending to most of the outstanding PRs for Windows things already present.

I can get the copy, file, and template modules all working just by adding a file.ps1 and copy.ps1 module to my custom modules directory. I have posted the two modules as gists…

https://gist.github.com/8a0b49f3c8b0ea4575c6.git
https://gist.github.com/fd92ba9af0e0309614ee.git

I hope these gists will be a good starting point for whomever figures out how to add these features into the ansible core. These do the bare minimum to work, they do not do any file permissions for example ( there is a stub of a function in the file.ps1 but it is never called because I never got it working ).

Thanks, Tony! Are you planning to add docs and submit a PR for these
modules?

FYI, the browser-friendly URLs for these gists:

https://gist.github.com/tkinz27/8a0b49f3c8b0ea4575c6
https://gist.github.com/tkinz27/fd92ba9af0e0309614ee

The only reason I had not done that already was I felt my approach was kinda hacky and didn’t know if ansible wanted to go down this route. For instance the file.ps1 module does not accept all of the same parameters as the normal file module. I tried to make a file permissions function that would take a perms: “0664” and somehow convert that to windows permissions but I never could get it working and we decided we did not need it at the moment for the project I am working on. I am really new to powershell and .NET programming. In retrospect I would think there should be a module that can takes in more windows native options for file permissions anyways.

I have no problem adding some documentation and submitting a pull request with what I have already. I just do not have a whole lot of time to try to develop a more complete solution.

Tony

Nice one Tony! Looking forward to testing!

As for the permissions stuff: IMHO, the Linux and Windows permissions models are just too far apart. There’s no way we’ll be able to replicate the (nix) params one to one over to Windows. Better to provide GREAT windows support than a lacky nix emulation. Let’s just call them what they are: Very different OS’es.