Project

General

Profile

Actions

Support #26036

closed

Windows templates are still not working with v1.21

Added by John D. about 5 years ago. Updated about 5 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
Templates
Target version:
-
Triaged:
No
Fixed in Releases:
Found in Releases:

Description

See issue: https://projects.theforeman.org/issues/25569#change-118023

Upgraded Foreman to 1.21

Windows Finish

<%#
kind: finish
name: Wimaging default finish
oses:
- Windows Server 2008
- Windows Server 2008 R2
- Windows Server 2012
- Windows Server 2012 R2
- Windows
# Parameters are expected to be set in Foreman (globally or per group/host)
params:
- windowsLicenseKey: ABCDE-ABCDE-ABCDE-ABCDE-ABCDE # Valid Windows license key
- windowsLicenseOwner: Company, INC # Legal owner of the Windows license key
- localAdminAccountDisabled: false
- ntpSever: time.windows.com,other.time.server
- domainAdminAccount: administrator@domain.com # use this account to join domain
- domainAdminAccountPasswd: Password for the domain Admin account
- computerOU: OU=Computers,CN=domain,CN=com # Place the computer account in specified Organizational Unit
- computerDomain: domain.com # domain to join
- foremanDebug: false
%>
<%
  # safemode renderer does not support unary negation
  pm_set = @host.puppetmaster.empty? ? false : true
  puppet_enabled = pm_set || @host_param('force-puppet') && @host_param('force-puppet') == 'true'
  salt_enabled = @host_param('salt_master') ? true : false
  chef_enabled = @host.respond_to?(:chef_proxy) && @host.chef_proxy
%>

@echo off
<% unless @host_param('localAdminAccountDisabled') -%>
  echo Activating administrator
  net user administrator /active:yes
<% end -%>

<% if @host.pxe_build? %>
  set ctr=0
  set nettimeout=10

  (echo Updating time)
  (sc config w32time start= auto)
  sc start w32time
  :ntp_testip
    ::ipconfig /renew
    wget.exe <%= foreman_url('provision') %>
    if %errorlevel% == 0 goto ntp_testip_ok
    timeout /t 10 >NUL
    set /a ctr=ctr+1
    echo Retry network. Run %ctr% time(s)
    if %ctr% GTR %nettimeout% (
        echo Network error! Exiting.
        exit 1
        )
    goto ntp_testip
  :ntp_testip_ok

  echo Network test OK!

  <% if @host_param('ntpSever') %>
    echo setting time server
    w32tm /config /manualpeerlist:<%= @host_param('ntpSever') %> /syncfromflags:manual /update
  <% end %>

  echo sync time
  w32tm /resync
  w32tm /resync

  :: You can join your machine to the domain right here >

  <% if @host_param('domainAdminAccount') and @host_param('domainAdminAccountPasswd') -%>
    echo joining domain
    powershell.exe -OutputFormat text -ExecutionPolicy remotesigned -command c:\deploy\joinDomain.ps1
  <% end %>

  :: < You can join your machine to the domain right here

  <% if @host_param('localAdminAccountDisabled') %>
    echo Disabling %tempAdminUser%
    net user %tempAdminUser% %tempAdminUser% /active:no
  <% end %>

  <% if @host_param('foremanDebug') != true %>
    echo Safely remove wimaging files
    sdelete.exe -accepteula -p 2 -r c:\wimaging
    sdelete.exe -accepteula -p 2 c:\Windows\Panther\unattend.xml
    sdelete.exe -accepteula -p 2 C:\Windows\Setup\Scripts\SetupComplete.cmd
    sdelete.exe -accepteula -p 2 -r c:\minint
    sdelete.exe -accepteula -p 2 -r c:\wimaging
  <% end %>

  <% if snippets "Wimaging extraFinishCommands" -%>
    echo Running extra commands
    <%= snippets "Wimaging extraFinishCommands" %>
    echo Cleaning up extras
    sdelete.exe -accepteula -p 2 -r c:\extras
  <% end -%>

  <% if puppet_enabled %>
    echo Installing puppet
    start /w "" msiexec /qn /i C:\extras\puppet.msi PUPPET_AGENT_STARTUP_MODE=Manual PUPPET_MASTER_SERVER=<%= @host.puppetmaster -%> PUPPET_AGENT_ACCOUNT_DOMAIN=<%= @host.domain -%> PUPPET_AGENT_ACCOUNT_USER=administrator PUPPET_AGENT_ACCOUNT_PASSWORD="<%= @host.params['domainAdminAccountPasswd'] -%>" 
    echo set puppet to auto start
    sc config puppet start= auto
    sc query puppet
  <% end%>

  echo Tell foreman build has finished
  wget.exe <%= foreman_url('built') %>

  <% if @host_param('foremanDebug') != true %>
    echo Safely removing c:\deploy
    sdelete.exe -accepteula -p 2 -r c:\deploy  

    echo remove leftover directories
    rmdir /s /q c:\wimaging
    rmdir /s /q c:\minint
    rmdir /s /q c:\deploy
    rmdir /s /q c:\extras

    echo rebooting...
    shutdown /r /t 5
  <% end -%>  
<% end -%>

Error:

Warning! ERF22-6132 [Foreman::Renderer::Errors::SyntaxError]: Syntax error occurred while parsing the template Windows Finish, make sure you have all ERB tags properly closed and the Ruby syntax is valid. The Ruby error: (string):6 :: parse error on value "(" (tLPAREN2)

Can't find a syntax mistake here. Maybe i am blind.

Windows PXE

<%#
kind: PXELinux
name: Wimaging default PXELinux
oses:
- Windows Server 2008
- Windows Server 2008 R2
- Windows Server 2012
- Windows Server 2012 R2
- Windows
%>
DEFAULT menu
LABEL menu
     COM32 linux.c32 boot/wimboot
     APPEND initrdfile=<%= @host.operatingsystem.bootfile(medium_provider,:bcd) %>,<%= @host.operatingsystem.bootfile(medium_provider,:bootsdi) %>,<%= @host.operatingsystem.bootfile(medium_provider,:bootwim) %>

Error

Warning! There was an error rendering the Windows PXE template: undefined method '#bootfile' for Operatingsystem::Jail (Debian)


Related issues 1 (0 open1 closed)

Related to Foreman - Bug #25569: Windows templates: undefined method `medium_uri' for nil:NilClassClosedShimon ShteinActions
Actions #1

Updated by John D. about 5 years ago

Ignore the Windows PXE Output.. With this template everything is fine.
But the problem with the Finishing Template still exists.

Actions #2

Updated by Ondřej Pražák about 5 years ago

  • Project changed from Templates to Foreman
  • Category set to Templates
Actions #3

Updated by Ondřej Pražák about 5 years ago

  • Related to Bug #25569: Windows templates: undefined method `medium_uri' for nil:NilClass added
Actions #4

Updated by Tomer Brisker about 5 years ago

Looks like you have a mistake in the template, `@host_param` should all be `host_param` (without the `@`)

Actions #5

Updated by John D. about 5 years ago

Tomer Brisker wrote:

Looks like you have a mistake in the template, `@host_param` should all be `host_param` (without the `@`)

Jep right.. I will never learn it.. Thank you. Fixed it for now.

Actions #6

Updated by John D. about 5 years ago

  • Tracker changed from Bug to Support
  • Status changed from New to Resolved
Actions #7

Updated by John D. about 5 years ago

Fetch TFTP boot files for mac005056ba712a.levigo.de task failed with the following error: undefined method `pxedir' for #<Windows:xxxxxxxxx>

The pxedir def in the windows.rb is missing. Is this "normal" or should it be already exist in foreman 1.21 R4?

Actions #8

Updated by Lukas Zapletal about 5 years ago

Use "finish" template type for this content.

Actions #9

Updated by John D. about 5 years ago

Lukas Zapletal wrote:

Use "finish" template type for this content.

For a PXELinux template i should choose finish as template type?
How can i boot then?

Actions

Also available in: Atom PDF