Foreman-VMware - Cannot get puppet to run through customisation

Hi All,

I've installed the foreman-vmware module and so far it's been fine, I've
came to a point where I'm trying to provision a windows server from a
template, I was following this guide:

I cannot get the RunOnce commands to process, it validates using ruby
-ryaml -e "YAML.load_file'test.yaml'" but foreman keeps throwing the error:
Failed to create a compute vSphere (VMware) instance testwindows: (<unknown
>): found character that cannot start any token while scanning for the next
token at line 6 column 11

I've narrowed it down to this section of code:
guiRunOnce:
commandList:
- <%= powershell %> -Command "invoke-webrequest -Uri
http://st1aa3v10006/windows-puppet.ps1 -Outfile c:\windows-puppet.ps1"
- <%= powershell %> -Command ".\windows-puppet.ps1"
- <%= powershell %> -Command "invoke-webrequest -Uri <%=
foreman_url("built") %>"

I can provision and build without the above code just fine, can anyone see
where I'm going wrong?

The entire YAML (same as the example in the link):
<%-
powershell = '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
-ExecutionPolicy Unrestricted -NoLogo -NoProfile'
-%>

··· --- identity: Sysprep: guiRunOnce: commandList: - <%= powershell %> -Command "invoke-webrequest -Uri http://st1aa3v10006/windows-puppet.ps1 -Outfile c:\windows-puppet.ps1" - <%= powershell %> -Command "& '.\windows.ps1 -PuppetVersion 3.7.5'" - <%= powershell %> -Command "invoke-webrequest -Uri <%= foreman_url ("built") %>" guiUnattended: autoLogon: true autoLogonCount: 1 password: plainText: true value: 'testpass123' timeZone: 110 identification: joinWorkgroup: 'WORKGROUP' licenseFilePrintData: autoMode: 'perSeat' userData: computerName: <%= @host.shortname %> fullName: 'IT' orgName: 'inovex GmbH' productId: 'D2N9P-3P6X9-2R39C-7RTCD-MDVJX' nicSettingMap: - adapter: dnsDomain: <%= @host.domain %> dnsServerList: - <%= @host.subnet.dns_primary %> gateway: - <%= @host.subnet.gateway %> ip: <%= @host.ip %> subnetMask: <%= @host.subnet.mask %> globalIPSettings: dnsServerList: - <%= @host.subnet.dns_primary %> dnsSuffixList: - <%= @host.domain %> options: changeSID: true deleteAccounts: false

Any help would be greatly appreciated,

The powershell variable starts with a %, and I don't think this is at
all valid in YAML to start the array value (the command in this case)
with a percent when used in context:

  • <%= powershell %> -Command "& '.\windows.ps1 -PuppetVersion 3.7.5'"

If you can remove that, replace the path or prefix it with something
else (e.g. another command) then that might work around the problem.

When testing the syntax, you probably need to ensure you pass the
rendered template from the preview in Foreman so the variables are fully
expanded.

··· On 29/04/16 15:31, Paul wrote: > Hi All, > > I've installed the foreman-vmware module and so far it's been fine, I've > came to a point where I'm trying to provision a windows server from a > template, I was following this > guide: https://blog.inovex.de/deploying-windows-server-with-foreman-in-vsphere/ > > I cannot get the RunOnce commands to process, it validates using ruby > -ryaml -e "YAML.load_file'test.yaml'" but foreman keeps throwing the error: > > > Failedto create a compute vSphere (VMware)instance > testwindows:():found character that cannot start any token > whilescanning forthe nexttoken at line 6column 11 > > > > I've narrowed it down to this section of code: > > > guiRunOnce: > commandList: > -<%=powershell %>-Command"invoke-webrequest -Uri > http://st1aa3v10006/windows-puppet.ps1 -Outfile c:\windows-puppet.ps1" > -<%=powershell %>-Command".\windows-puppet.ps1" > -<%=powershell %>-Command"invoke-webrequest -Uri <%= > foreman_url("built") %>" > > > > I can provision and build without the above code just fine, can anyone > see where I'm going wrong? > > The entire YAML (same as the example in the link): > > > <%- > powershell > ='%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe > -ExecutionPolicy Unrestricted -NoLogo -NoProfile' > -%>


Dominic Cleal
dominic@cleal.org

As it happens I've just been testing the YAML myself in an IRB shell (thus
a caveat, not tested in Foreman itself) and the '%' seems ok, but it's not
happy with the rest of the rendered syntax.

If I change it such that single quotes enclose the whole of each line,
though, it loads ok:

$ cat /tmp/foo

··· --- identity: Sysprep: guiRunOnce: commandList: - '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command "invoke-webrequest -Uri http://st1aa3v10006/windows-puppet.ps1 -Outfile c:\windows-puppet.ps1"' - '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command "& \".\windows.ps1 -PuppetVersion 3.7.5\""' - '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command "invoke-webrequest -Uri http://foo/built"'

irb(main):041:0> pp YAML.load(File.read(’/tmp/foo’))
{“identity”=>
{“Sysprep”=>
{“guiRunOnce”=>
{“commandList”=>
["%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
-ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command
"invoke-webrequest -Uri http://st1aa3v10006/windows-puppet.ps1 -Outfile
c:\windows-puppet.ps1"",
"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
-ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command “&
\”.\windows.ps1 -PuppetVersion 3.7.5\""",
"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
-ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command
"invoke-webrequest -Uri http://foo/built""]}}}}

Note the middle line had to be altered to use escaped double quotes around
the "windows.ps1 … " call as the single quotes were breaking enclosing
the full line with singles - I have no idea if this breaks the actual call
on Windows, but at least the YAML validates.

All that said, I’d agree with Dominic - testing rendering via the "preview"
function on the template itself is the way to go.

We've been testing with the changed syntax, as follows:

This uses another way to download the files, as invoke-webrequest is
powershell 3.0+ only

 commandList:
  - &#39;%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe 

-ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command "(New-Object
System.Net.WebClient).DownloadFile(&quot;http://st1aa3v10006/windows-puppet.ps1&quot;,
&quot;c:\installpuppet.ps1&quot;)"'
- '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
-ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command "&
&quot;.\installpuppet.ps1 -PuppetVersion 3.8.7-x64&quot;"'
- '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
-ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command "(New-Object
System.Net.WebClient).DownloadFile(&quot;http://foreman/unattended/built?token=<%=
@host.token %>&quot;, &quot;c:\foremaninstalled.txt&quot;)"'

This results in no entries for the runonce we expect to be set in the
sysprep, and no downloaded file.
So somehow it still fails.

Will keep looking for any logging indicating an error.

··· On Monday, May 9, 2016 at 12:17:53 PM UTC+2, Greg Sutcliffe wrote: > > As it happens I've just been testing the YAML myself in an IRB shell (thus > a caveat, not tested in Foreman itself) and the '%' seems ok, but it's not > happy with the rest of the rendered syntax. > > If I change it such that single quotes enclose the whole of each line, > though, it loads ok: > > $ cat /tmp/foo > --- > identity: > Sysprep: > guiRunOnce: > commandList: > - '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe > -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command > "invoke-webrequest -Uri http://st1aa3v10006/windows-puppet.ps1 -Outfile > c:\windows-puppet.ps1"' > - '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe > -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command "& > \".\windows.ps1 -PuppetVersion 3.7.5\""' > - '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe > -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command > "invoke-webrequest -Uri http://foo/built"' > > irb(main):041:0> pp YAML.load(File.read('/tmp/foo')) > {"identity"=> > {"Sysprep"=> > {"guiRunOnce"=> > {"commandList"=> > ["%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe > -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command > \"invoke-webrequest -Uri http://st1aa3v10006/windows-puppet.ps1 -Outfile > c:\\windows-puppet.ps1\"", > "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe > -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command \"& > \\\".\\windows.ps1 -PuppetVersion 3.7.5\\\"\"", > "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe > -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command > \"invoke-webrequest -Uri http://foo/built\""]}}}} > > Note the middle line had to be altered to use escaped double quotes around > the "windows.ps1 ... " call as the single quotes were breaking enclosing > the full line with singles - I have no idea if this breaks the actual call > on Windows, but at least the YAML validates. > > All that said, I'd agree with Dominic - testing rendering via the > "preview" function on the template itself is the way to go. >

Okay,

We have gotten a bit further:

the command list as posted above never makes it into the unattend.xml.

We have tried a similar powershell command from vmware customization, which
goes without problems.

%SystemRoot%\System32
WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -NoLogo
-NoProfile -Command "echo wood > c:\temp.txt"

and shows up in the unattend.xml

So my guess is something goes awry in the fog interface with vmware
customization?

··· On Monday, May 9, 2016 at 4:08:32 PM UTC+2, Finke Lamein wrote: > > > On Monday, May 9, 2016 at 12:17:53 PM UTC+2, Greg Sutcliffe wrote: >> >> As it happens I've just been testing the YAML myself in an IRB shell >> (thus a caveat, not tested in Foreman itself) and the '%' seems ok, but >> it's not happy with the rest of the rendered syntax. >> >> If I change it such that single quotes enclose the whole of each line, >> though, it loads ok: >> >> $ cat /tmp/foo >> --- >> identity: >> Sysprep: >> guiRunOnce: >> commandList: >> - '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe >> -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command >> "invoke-webrequest -Uri http://st1aa3v10006/windows-puppet.ps1 -Outfile >> c:\windows-puppet.ps1"' >> - '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe >> -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command "& >> \".\windows.ps1 -PuppetVersion 3.7.5\""' >> - '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe >> -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command >> "invoke-webrequest -Uri http://foo/built"' >> >> irb(main):041:0> pp YAML.load(File.read('/tmp/foo')) >> {"identity"=> >> {"Sysprep"=> >> {"guiRunOnce"=> >> {"commandList"=> >> ["%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe >> -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command >> \"invoke-webrequest -Uri http://st1aa3v10006/windows-puppet.ps1 -Outfile >> c:\\windows-puppet.ps1\"", >> "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe >> -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command \"& >> \\\".\\windows.ps1 -PuppetVersion 3.7.5\\\"\"", >> "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe >> -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command >> \"invoke-webrequest -Uri http://foo/built\""]}}}} >> >> Note the middle line had to be altered to use escaped double quotes >> around the "windows.ps1 ... " call as the single quotes were breaking >> enclosing the full line with singles - I have no idea if this breaks the >> actual call on Windows, but at least the YAML validates. >> >> All that said, I'd agree with Dominic - testing rendering via the >> "preview" function on the template itself is the way to go. >> > > We've been testing with the changed syntax, as follows: > > This uses another way to download the files, as invoke-webrequest is > powershell 3.0+ only > > commandList: > - '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe > -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command "(New-Object > System.Net.WebClient).DownloadFile(\" > http://st1aa3v10006/windows-puppet.ps1\", \"c:\installpuppet.ps1\")"' > - '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe > -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command "& > \".\installpuppet.ps1 -PuppetVersion 3.8.7-x64\""' > - '%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe > -ExecutionPolicy Unrestricted -NoLogo -NoProfile -Command "(New-Object > System.Net.WebClient).DownloadFile(\" > http://foreman/unattended/built?token=<%= @host.token %>\", > \"c:\foremaninstalled.txt\")"' > > This results in no entries for the runonce we expect to be set in the > sysprep, and no downloaded file. > So somehow it still fails. > > Will keep looking for any logging indicating an error. >