Packer fails during windows template creation

Hi there,
I have a question regarding packer - Windows Server Template creation.
Everything is going fine until the last step.

There will be powershell script to install Active Directory Domain Services and Create a forest on the target server. It works fine. then when Packer sends shutdown command to convert the vm into template, it fails.
The reason of failing is, windows has [ applying settings screen ] loading. it takes a lot of time for some reason; when I tested manually. Eventually it works (manually no packer) - Just need to wait.

The problem im facing that Packer is not waiting more than 11 minutes. then it fails and destory the VM

Any ideas how to let packer wait for 30 minutes if that is possible? and why 11 minutes. is that a value that i can chage?

Thanks in advance.

Best regards,
DevOps Newbie.

Outpute of the error: (at this time the windows will be on screen [ Applying settings % ]

==> vsphere-iso: Shutting down VM…
==> vsphere-iso: Provisioning step had errors: Running the cleanup provisioner, if present…
==> vsphere-iso: Clear boot order…
==> vsphere-iso: Deleting Floppy image …
==> vsphere-iso: Destroying VM…
==> vsphere-iso: The attempted operation cannot be performed in the current state (Powered on).
Build ‘vsphere-iso’ errored after 11 minutes 32 seconds: The operation is not allowed in the current state.

==> Wait completed after 11 minutes 32 seconds

==> Some builds didn’t complete successfully and had errors:
→ vsphere-iso: The operation is not allowed in the current state.

==> Builds finished but no artifacts were created.

The 11 minutes is the entire length of the Packer build, not just the wait.

The destroy thing is interesting but I think less important than " ==> vsphere-iso: Provisioning step had errors: Running the cleanup provisioner, if present…"

That means one of your provisioners failed. Probably the “destroy” error is because the vm wasn’t destroyed cleanly because of these errors. Can you run with the environment variable PACKER_LOG=1 set to gather more information about what happened in the provisioning run?

Hi
As i said before, the reason it fails is due to Windows Applying settings screen after installing Active directory. Packer trying to shut the machine down to convert it into template. But windows apply settings take more than 11 minutes and therefore it is failing.

My issue I want to tell Packer to wait more than 11 minutes.

==> vsphere-iso: Shutting down VM…
2021/03/24 22:16:26 [INFO] 0 bytes written for ‘stderr’
2021/03/24 22:16:26 [INFO] RPC client: Communicator ended with: 0
2021/03/24 22:16:26 [INFO] RPC endpoint: Communicator ended with: 0
2021/03/24 22:16:26 packer-provisioner-powershell plugin: [INFO] 0 bytes written for ‘stdout’
2021/03/24 22:16:26 packer-provisioner-powershell plugin: [INFO] 0 bytes written for ‘stderr’
2021/03/24 22:16:26 packer-provisioner-powershell plugin: [INFO] RPC client: Communicator ended with: 0
2021/03/24 22:16:26 [INFO] (telemetry) ending powershell
2021/03/24 22:16:26 packer-builder-vsphere-iso plugin: **

Waiting max 5m0s for shutdown to complete

**

==> vsphere-iso: Provisioning step had errors: Running the cleanup provisioner, if present...
==> vsphere-iso: Clear boot order...
==> vsphere-iso: Deleting Floppy image ...
2021/03/24 22:21:27 packer-builder-vsphere-iso plugin: Deleting floppy disk: /tmp/packer125519848
==> vsphere-iso: Destroying VM...
2021/03/24 22:21:27 [INFO] (telemetry) ending vsphere-iso
==> vsphere-iso: The attempted operation cannot be performed in the current state (Powered on).
==> Wait completed after 11 minutes 35 seconds
2021/03/24 22:21:27 machine readable: error-count []string{"1"}
Build 'vsphere-iso' errored after 11 minutes 35 seconds: The operation is not allowed in the current state.
==> Some builds didn't complete successfully and had errors:

2021/03/24 22:21:27 machine readable: vsphere-iso,error []string{"The operation is not allowed in the current state."}
==> Wait completed after 11 minutes 35 seconds
==> Builds finished but no artifacts were created.

2021/03/24 22:21:27 [INFO] (telemetry) Finalizing.
==> Some builds didn't complete successfully and had errors:
--> vsphere-iso: The operation is not allowed in the current state.

==> Builds finished but no artifacts were created.
2021/03/24 22:21:28 waiting for all plugin processes to complete...
2021/03/24 22:21:28 /usr/local/bin/packer: plugin process exited
2021/03/24 22:21:28 /usr/local/bin/packer: plugin process exited
2021/03/24 22:21:28 /usr/local/bin/packer: plugin process exited

This is the last line I see. Then after 5 to 6 mins the rest appears as a failure as you can see it waits max 5 min. Cant we change that? I couldn’t find any option.

As you can I see I can control for how long it waits an IP address via the following:
“ip_wait_timeout”: “1h”,

I want something similar for shutting down to force packer to wait 30 min after issuing shutdown.

This option works for all provisioners to prevent provisioners themselves from running for a given wait: provisioner - build - Blocks | Packer by HashiCorp

This is your shutdown timeout:

1 Like

Thank you very much for your help.
Do you have any example where to place that code?

shutdown_timeout (duration string | ex: “1h5m2s”) - Amount of time to wait for graceful VM shutdown. Defaults to 5m or five minutes. This will likely need to be modified if the communicator is ‘none’.

Any example?
I placed it under builders:

"builders": [

  {

    "ip_wait_timeout": "1h",

    **"shutdown_timeout": "1h",**

    "type": "vsphere-iso",

    "vcenter_server": "{{user `vsphere-server`}}",

    "username": "{{user `vsphere-user`}}",

    "password": "{{user `vsphere-password`}}",

    "insecure_connection": "true",
}

I don’t think I have the syntax correctly… I don’t understand the Communicator part.

I’m still unable to change this value
2021/03/25 01:33:47 packer-builder-vsphere-iso plugin: Waiting max 5m0s for shutdown to complete

If anyone has code example how to change it, please share it.

I was able to change the value of “shutdown_timeout”.
Thank you @SwampDragons for your help. Highly appreciated.