joefitzgerald / packer-windows

Windows Packer Templates
MIT License
1.63k stars 1.12k forks source link

Creating a Windows 2012 Server Domain Controller image using Packer #178

Closed 3goats closed 8 years ago

3goats commented 8 years ago

Hi,

I'm trying to create a Windows 2012 Server Domain Controller by adding a Packer PowerShell provisioner. I have the following PS that is called from the Packer provisioner. e.g.

{
  "type": "powershell",
  "script": ["./scripts/InstallNewForest.ps1"]
} 

The PS Script looks like this:

$Password = ConvertTo-SecureString -AsPlainText -String "Passw0rd1£@3451" -Force

# Create New Forest, add Domain Controller
$domainname = "contoso.com"
$netbiosName = "CONTOSO"

  Import-Module ADDSDeployment
  Install-ADDSForest `
   -CreateDnsDelegation:$false `
   -SafeModeAdministratorPassword $Password `
   -DatabasePath "C:\Windows\NTDS" `
   -DomainMode "Win2012" `
   -DomainName $domainname `
   -DomainNetbiosName $netbiosName `
   -ForestMode "Win2012" `
   -InstallDns:$true `
   -LogPath "C:\Windows\NTDS" `
   -NoRebootOnCompletion:$true `
   -SysvolPath "C:\Windows\SYSVOL" `
   -Force:$true

This all appears to run OK. I then initiate the Windows reboot using the Packer provisioner. Like this:

{
  "type": "windows-restart"
}

This restarts the machine as expected and Packer continues to create a working image.

However, when I then boot and login into the new image the server is prompting me to run the DC Promo wizard. If I try setting the -NoRebootOnCompletion:$true to $false and run the PS script manually it works as expected.

StefanScherer commented 8 years ago

What about setting it to $false and don't use the windows-restart provisioner. Packer has a builtin retry to start the next provision script.

I've done this some days ago in the provision script install-containers.bat The corresponding packer template has a list of provision scripts.

Packer just starts the next provision script after WinRM or OpenSSH is back up and running after the reboot.

Perhaps this way works better. Just my two cents.

DenverOps commented 8 years ago

@carlskii Did you ever get this working? I am trying to solve this issue as well.

sneal commented 8 years ago

Closing for now, we can re-open in the future if required.