Packer failed to continue running the template after the PowerShell domain join command was executed.
This issue has been here for a while, I did raise this issue as a bug but @Mathew suggested me to update the plugins which I already did, and also to wait for the latest release which could possibly fix my issue, but the issue still has not been resolved and I believe this is a bug and hopefully there would be someone to investigate this bug. Thanks so much.
As I need to add the temporary VM which is generated by Packer during the build into the domain, I have added a Domain join PowerShell script into the template which looks like this:
$domain = "xxxxx"
$password = "xxxxx" | ConvertTo-SecureString -asPlainText -Force
$username = "$domain\aaa.bbb"
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Add-Computer -DomainName $domain -Credential $credential
and then in the provisioners part of the template, I have placed the domain join script before the windows-restart command.
{ "type": "powershell",
"script": "PackerUpload/join_domain.ps1" },
{ "type": "windows-restart",
"restart_check_command": "powershell -command \"& {Write-Output 'restarted.'}\"" }
Technically, Packer is supposed to restart and continue the running other components in the template. However, I don't know why the packer build failed to restart or even run another script (I did attempt to replace the windows-restart with another PowerShell script, but it also failed to run). I might suspect that the domain join script has somehow disconnected the temporary VM with Packer or maybe Packer failed to reconnect the VM after the domain join script had been successfully executed. I guess this may be a bug in Packer. I have attached the debug_log below. There is no problem if I run other PowerShell scripts (not domain join one), the connection is fine and windows-restart works fine. Thank you.
Info:
PACKER_LOG=1 packer build template.json.--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/76298b3c-1137-4eed-bb1d-dc7d253dd191%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
$domain = "xxxxx"
$password = "xxxxx" | ConvertTo-SecureString -asPlainText -Force
$username = "$domain\aaa.bbb"
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/76298b3c-1137-4eed-bb1d-dc7d253dd191%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--Alvaro
{ "variables": { "client_id": "{{env `AZURE_CLIENT_ID`}}", "client_secret": "{{env `AZURE_CLIENT_SECRET`}}", "tenant_id": "{{env `AZURE_TENANT_ID`}}", "subscription_id": "{{env `AZURE_SUBSCRIPTION_ID`}}", "object_id": "{{env `AZURE_OBJECT_ID`}}" }, "builders": [{ "type": "azure-arm",
"client_id": "{{user `client_id`}}", "client_secret": "{{user `client_secret`}}", "tenant_id": "{{user `tenant_id`}}", "subscription_id": "{{user `subscription_id`}}", "object_id": "{{user `object_id`}}",
"managed_image_resource_group_name": "MyPacker", "managed_image_name": "myPackerImage",
"virtual_network_name": "------", "virtual_network_subnet_name": "-----", "virtual_network_resource_group_name": "Networking",
"os_type": "Windows", "image_publisher": "MicrosoftWindowsServer", "image_offer": "WindowsServer", "image_sku": "2016-Datacenter",
"disk_additional_size": "12",
"communicator": "winrm", "winrm_use_ssl": "true", "winrm_insecure": "true", "winrm_timeout": "10m", "winrm_username": "packer",
"azure_tags": { "dept": "Engineering", "task": "Image deployment" },
"location": "australiasoutheast", "vm_size": "Standard_DS2_v2" }], "provisioners": [ { "type": "powershell", "inline": ["mkdir c:\\Packer"] }, { "type": "file", "source": "ToUpload/", "destination": "c:\\Packer" }, { "type": "windows-restart", "restart_check_command": "powershell -command \"& {Write-Output 'restarted.'}\"" }, { "type": "windows-restart", "restart_check_command": "powershell -command \"& {Write-Output 'restarted.'}\"" }, { "type": "powershell", "script": "ToUpload/join_domain.ps1" }, { "type": "windows-restart", "restart_check_command": "powershell -command \"& {Write-Output 'restarted.'}\"" }, { "type": "powershell", "inline": [ "Add-WindowsFeature Web-Server", "if( Test-Path $Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml ){ rm $Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml -Force}", "& $Env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /quiet /quit" ] }]}