Timeout waiting for machine to restart after running a Domain Join script in Packer Azure template

1,015 views
Skip to first unread message

Sim

unread,
Mar 28, 2018, 7:41:57 PM3/28/18
to Packer
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 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.'}\""
    }

However, I don't know why the build failed because it was waiting for the machine to restart. It did run the domain join script I believe. I even did add some "windows_restart" params in the packer template like:
"pause_before": "60s",
"restart_timeout": "10m",

still didn't work, it still kept waiting and failed to continue to run other parts in the template. 

Has anyone encountered this issue before? Thank you. 

Alvaro Miranda Aguilera

unread,
Mar 29, 2018, 5:34:45 AM3/29/18
to packe...@googlegroups.com
Do you have any way to get to the console in AZURE and confirm the VM got restarted error free?

Sometimes windows will use the restart to install some updates, etc.

So checking the console may help.

Alvaro


--
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/54b84fbc-4c02-4810-b0df-0e483a8ee981%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Sim

unread,
Mar 30, 2018, 9:05:07 PM3/30/18
to Packer
==>azure-arm: Provisioning with shell script: PackerUpload/join_domain.ps1
    azure-arm: WARNING: The changes will take effect after you restart the computer tmppackervm.
==> azure-arm: Pausing 6m0s before the next provisioner...
==> azure-arm: Restarting Machine
==> azure-arm:
==> azure-arm: Cleanup requested, deleting resource group ...

This is the console, it ran the DomainJoin script, but when it moved to execute the windows_restart. It couldn't restart the VM because of the timeout. I suspect it may be because of the domain_join script somehow automatically restarted the VM after adding the VM into the domain or maybe it was prompting something and waiting for user input. Not quite sure if there is any ideas of how to optimise the domain_join script so it wont restart the VM. Thank you. 
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.



--
Alvaro

Alvaro Miranda Aguilera

unread,
Apr 2, 2018, 5:47:48 PM4/2/18
to packe...@googlegroups.com
run this with debug mode

set PACKER_LOG=1

checking the sequence I would assume the restart work but the exit code wasn;t 0, that could explain it started the clean up process

if you run this in debug mode, we should be able to see more, like the exit code before the clean up process

alvaro

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/8fa36ae6-afe6-4601-9d7c-1db1cb5e53b9%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Message has been deleted

Sim

unread,
Apr 3, 2018, 7:53:50 AM4/3/18
to Packer
This was the console output when I set PACKER_LOG=1, it did not give much info about it :( 

2018/04/03 12:37:06 ui:     azure-arm: VERBOSE: Performing the operation "Join in domain '@@@@@'" on target "tmppackervm".
    azure-arm: VERBOSE: Performing the operation "Join in domain '@@@@@'" on target "tmppackervm".
2018/04/03 12:37:07 packer.exe: 2018/04/03 12:37:07 [INFO] command 'powershell "& { $env:PACKER_BUILDER_TYPE=\"azure-arm\"; $env:PACKER_BUILD_NAME=\"azure-arm\"; c:/Windows/Temp/script.ps1; exit $LastExitCode}"' exited with code: 0
2018/04/03 12:37:07 packer.exe: 2018/04/03 12:37:07 [INFO] RPC endpoint: Communicator ended with: 0
2018/04/03 12:37:07 [INFO] 308 bytes written for 'stdout'
    azure-arm: WARNING: The changes will take effect after you restart the computer tmppackervm.
    azure-arm: about to restart world
2018/04/03 12:37:07 [INFO] 0 bytes written for 'stderr'
2018/04/03 12:37:07 [INFO] RPC client: Communicator ended with: 0
2018/04/03 12:37:07 [INFO] RPC endpoint: Communicator ended with: 0
2018/04/03 12:37:07 ui:     azure-arm: WARNING: The changes will take effect after you restart the computer tmppackervm.
    azure-arm:
2018/04/03 12:37:07 packer-provisioner-powershell.exe: 2018/04/03 12:37:07 [INFO] 0 bytes written for 'stderr'
2018/04/03 12:37:07 packer-provisioner-powershell.exe: 2018/04/03 12:37:07 [INFO] 308 bytes written for 'stdout'
2018/04/03 12:37:07 packer-provisioner-powershell.exe: 2018/04/03 12:37:07 [INFO] RPC client: Communicator ended with: 0
2018/04/03 12:37:07 ui:     azure-arm: debugg
    azure-arm:
2018/04/03 12:37:07 ui:     azure-arm:

2018/04/03 12:37:07 ui:     azure-arm:
    azure-arm:
2018/04/03 12:37:07 [INFO] (telemetry) ending powershell
2018/04/03 12:37:07 [INFO] (telemetry) Starting provisioner windows-restart
2018/04/03 12:37:07 ui: ==> azure-arm: Restarting Machine
==> azure-arm: Restarting Machine
2018/04/03 12:37:07 packer.exe: 2018/04/03 12:37:07 [INFO] starting remote command: shutdown /r /f /t 0 /c "packer restart"
2018/04/03 12:37:07 packer.exe: 2018/04/03 12:37:07 [INFO] command 'shutdown /r /f /t 0 /c "packer restart"' exited with code: 0
2018/04/03 12:37:07 packer.exe: 2018/04/03 12:37:07 [INFO] RPC endpoint: Communicator ended with: 0
==> azure-arm: Waiting for machine to restart...
2018/04/03 12:37:07 [INFO] 0 bytes written for 'stderr'
2018/04/03 12:37:07 [INFO] 0 bytes written for 'stdout'
2018/04/03 12:37:07 [INFO] RPC client: Communicator ended with: 0
2018/04/03 12:37:07 [INFO] RPC endpoint: Communicator ended with: 0
2018/04/03 12:37:07 packer.exe: 2018/04/03 12:37:07 [INFO] 0 bytes written for 'stderr'
2018/04/03 12:37:07 packer.exe: 2018/04/03 12:37:07 [INFO] 0 bytes written for 'stdout'
2018/04/03 12:37:07 packer.exe: 2018/04/03 12:37:07 [INFO] RPC client: Communicator ended with: 0
2018/04/03 12:37:07 ui: ==> azure-arm: Waiting for machine to restart...
2018/04/03 12:37:08 packer.exe: 2018/04/03 12:37:08 Check if machine is rebooting...
2018/04/03 12:37:08 [INFO] 0 bytes written for 'stderr'
2018/04/03 12:37:08 [INFO] 0 bytes written for 'stdout'
2018/04/03 12:37:08 packer.exe: 2018/04/03 12:37:08 [INFO] 0 bytes written for 'stdout'
2018/04/03 12:37:08 packer.exe: 2018/04/03 12:37:08 Waiting for machine to become available...
2018/04/03 12:37:08 packer.exe: 2018/04/03 12:37:08 Checking that communicator is connected with: 'powershell -command "& {Write-Output 'restarted.'}"'
2018/04/03 12:37:08 packer.exe: 2018/04/03 12:37:08 [INFO] 0 bytes written for 'stderr'
2018/04/03 12:37:08 packer.exe: 2018/04/03 12:37:08 Waiting for machine to reboot with timeout: 5m0s
2018/04/03 12:37:34 [INFO] 0 bytes written for 'stderr'
2018/04/03 12:37:34 [INFO] 0 bytes written for 'stdout'
2018/04/03 12:37:34 packer.exe: 2018/04/03 12:37:34 [INFO] 0 bytes written for 'stdout'
2018/04/03 12:37:34 packer.exe: 2018/04/03 12:37:34 [INFO] 0 bytes written for 'stderr'
2018/04/03 12:37:34 packer.exe: 2018/04/03 12:37:34 Communication connection err: unknown error Post https://--.--.--.--:----/wsman: dial tcp ------: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
2018/04/03 12:37:49 [INFO] 0 bytes written for 'stderr'
2018/04/03 12:37:49 [INFO] 0 bytes written for 'stdout'
2018/04/03 12:37:49 packer.exe: 2018/04/03 12:37:49 [INFO] 0 bytes written for 'stdout'
2018/04/03 12:37:49 packer.exe: 2018/04/03 12:37:49 [INFO] 0 bytes written for 'stderr'
2018/04/03 12:37:49 packer.exe: 2018/04/03 12:37:49 Communication connection err: http response error: 401 - invalid content type

2018/04/03 12:42:07 ui error: ==> azure-arm: Timeout waiting for machine to restart.
==> azure-arm: Timeout waiting for machine to restart.
2018/04/03 12:42:07 packer.exe: 2018/04/03 12:42:07 Communicator wait canceled, exiting loop
==> azure-arm:
2018/04/03 12:42:07 [INFO] (telemetry) ending windows-restart
==> azure-arm: Cleanup requested, deleting resource group ...
2018/04/03 12:42:07 ui: ==> azure-arm:
Reply all
Reply to author
Forward
0 new messages