We're trying to build a windows image. The script looks like this:
"provisioners": [
{
"type": "powershell",
"inline": [
"refreshenv"
]
},
{
"type": "powershell",
"inline": [
"Write-Host \"Installing applications\"",
"Start-Process choco -PassThru -ArgumentList 'install -y awscli 7zip.install' -NoNewWindow -Wait",
"cat C:\\ProgramData\\chocolatey\\logs\\chocolatey.log"
]
},
{
"type": "windows-shell",
"inline": [
"aws s3 cp ...",
]
},
choco is installed, and the installation of the awscli starts, but the packer process continues before the process has finished installing. The offending logs look like this:
```
amazon-ebs: Ensuring chocolatey commands are on the path
amazon-ebs: Ensuring chocolatey.nupkg is in the lib folder
amazon-ebs: Refreshing environment variables from registry for cmd.exe. Please wait...Finished..
==> amazon-ebs: Provisioning with Powershell...
==> amazon-ebs: Provisioning with powershell script: /var/folders/pw/wy4vnj7n48g5lmq6m94xwl880000gn/T/packer-powershell-provisioner725332409
amazon-ebs: Installing applications
amazon-ebs:
amazon-ebs: Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
amazon-ebs: ------- ------ ----- ----- ------ -- -- -----------
amazon-ebs: 70 6 1016 3712 0.08 3476 0 choco
amazon-ebs: Chocolatey v0.10.11
amazon-ebs: Installing the following packages:
amazon-ebs: awscli;7zip.install
amazon-ebs: By installing you accept licenses for the packages.
amazon-ebs: Progress: Downloading awscli 1.15.41... 100%
amazon-ebs:
amazon-ebs: awscli v1.15.41 [Approved]
amazon-ebs: awscli package files install completed. Performing other installation steps.
amazon-ebs: Downloading awscli 64 bit
amazon-ebs: Progress: 100% - Completed download of C:\Users\admin\AppData\Local\Temp\chocolatey\awscli\1.15.41\AWSCLI64-1.15.41.msi (10.39 MB).
amazon-ebs: Download of AWSCLI64-1.15.41.msi (10.39 MB) completed.
==> amazon-ebs: Provisioning with windows-shell...
==> amazon-ebs: Provisioning with shell script: /var/folders/pw/wy4vnj7n48g5lmq6m94xwl880000gn/T/packer-windows-shell-provisioner359973109
amazon-ebs:
amazon-ebs: 'aws' is not recognized as an internal or external command,
amazon-ebs: operable program or batch file.
amazon-ebs:
```
You can see that it has continued before the choco process has finished installing everything and the subsequent aws call fails.
These commands work when you run them manually. I've tried running it as a windows-shell provisioner rather than a powershell one and I see the same result. I've tried various configurations of Start-Process (e.g. returning a variable and waiting on that, etc.) and can't find a consistent way of fixing this.
Does anyone have any experience of working with choco and packer? Is there anything obvious that I'm doing wrong?