Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provisionner "windows-restart" doesn't work #12663

Closed
Hassan1er opened this issue Oct 24, 2023 · 4 comments
Closed

Provisionner "windows-restart" doesn't work #12663

Hassan1er opened this issue Oct 24, 2023 · 4 comments

Comments

@Hassan1er
Copy link

Hello,

I'm using Packer throught Azure Pipelines to create Windows Server 2022 image. The VM is created with Hyper-V.
Here is my problem : After launching my hardening script on the VM, i try to use the provisionner "windows-restart", but it doesn't work.
The VM is not restarting, and the Azure Pipeline fails after the 10 minutes timeout. At the same time, i'm looking at the VM on Hyper-V to see what is going on, but nothing happens. The VM doesn't even shutdown to start again, it just stays on the desktop and nothing happens. I already tried to restart the machine manually, but the Azure Pipeline doesn't detect it, and still fails after 10 minutes. I tried to increase the restart timeout to 30m, but nothing changes. I tried to put a pause_before with 2m, but nothing changes. I also tried to restart the machine with a Powershell script, but the same thing happens, the VM doesn't restart and the pipeline fails. I don't know what to do more.

Thanks a lot for your help!

Here is the part of my script :
2023-10-24_11h28_59

Here is the pipeline fail. My hardening script is launched at line 296. The provisionner "windows-restart" is launched at line 307. Between the lines 307 and 308, there is a wait of 10m corresping to the restart_timeout.
2023-10-24_11h33_50

@Hassan1er Hassan1er added the bug label Oct 24, 2023
@nywilken
Copy link
Contributor

Hi @Hassan1er thanks for reaching out. The error message at the end of your log 401 - invalid content type is an indicator that Packer is unable to communicate with WinRM, which is needed for running the provisioner. Which may be the reason why windows-reboot is not executing. If you can enable debug logs PACKER_LOG=1 in the pipeline you may be able to see more error information.

Does your hardening script disable WinRM or prevent remote logins?

Hardening scripts tend to disable all Packer communication to the instance so we recommend running hardening scripts as the last provisioner with the reboot being part of the hardening step if the reboot. The Powershell command doesn't have an expect_disconnect attribute to inform Packer that it will reboot. But you can add the [pause_after](https://developer.hashicorp.com/packer/docs/provisioners/powershell#pause_after) to the provisioner to have Packer wait a number of minutes for the machine to reboot after running the hardening scripts.

I don't suspect this is a bug so I will label it as so. But I will keep the issue open for your comments and discussion.

@Hassan1er
Copy link
Author

Hi @nywilken thanks for your answer. My hardening script doesn't disable WinRM or prevent remote logins. I'm alreay using it for 2016 and 2019 images, and it works perfectly. The problem only appears with 2022. The Packer Log doesn't give me utile informations about the error.

@Hassan1er
Copy link
Author

After investigations, i found the issue with my problem. The hardening was effictively blocking WinRM. After changes, the pipeline was able to continue the process and the image is being created succesfully. Thanks.

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants