I have a packer
template that I'm trying to run. It generally does what I want it to do in that it creates an Azure VM, generalizes it and uploads it to a compute gallery. I'm now trying to expand it to install an application via Powershell
script. The problem is that I can't figure out where the script should be or how I should be calling it in the template.
I've looked at various examples in which people have used different formats such as using relative paths, e.g. script = "./install_app.ps1"
, or just calling the script name itself, e.g. script = "install_app.ps1"
. I've tried it both ways only to get an error from packer
.
Error: Failed preparing provisioner-block "powershell" ""
on .\win10Packer.pkr.hcl line 56:
(source code not available)
1 error(s) occurred:
* Bad script './install_app.ps1': CreateFile ./install_app.ps1: The system
cannot find the file specified.
My build{}
section:
build {
sources = ["source.azure-arm.autogenerated_1"]
provisioner "powershell" {
inline = ["Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted","Install-Module PSCompression"]
}
provisioner "powershell" {
script = "./install_npp.ps1"
}
provisioner "powershell" {
inline = ["& $env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /quiet /quits", "while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10 } else { break }}"]
}
}
install_app.ps1.ps1
.