0

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 }}"]
   }

}
1
  • I believe I figured out the issue: I inadvertently named my script install_app.ps1.ps1.
    – theillien
    Nov 15 at 21:16

1 Answer 1

1

A provisioner needs to be declared like this

"provisioners": [
    {
      "type": "powershell",
      "script": "path/to/your/script.ps1"
    }
    // Add more provisioners or scripts as needed
  ]

So I think your template is wrong declared

1
  • For clarity, now that I know, the path is relative to where to the template is.
    – theillien
    Dec 1 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .