Packer: Feature: CustomScriptExtension for Azure builder

Created on 31 Jul 2018  ยท  13Comments  ยท  Source: hashicorp/packer

Hi,

I'm running lots of packer on Azure and I was wondering if there's a way to run a script via packer on instance boot (just like EC2 user data) on Azure.
Azure itself has the CustomScriptExtension (https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows) but I can't see a way to do this via packer.
This is quite important for things that need to run that might break the packer process.

For example I'm reconfiguring winrm in some builds which seems to break the packer process. On AWS I always put that into user data.

Thanks,
David

buildeazure duplicate enhancement windows-guest

Most helpful comment

@paulmey Based on some reading and googling, I'm under the impression that what's being asked for here (custom_data_file that can run against windows vms) isn't actually an option in Azure. Is that correct? If I'm wrong, can you point me to some docs for the tool so I can try to implement this feature?

All 13 comments

You referenced the custom extension for Windows, but do you mean for Windows VMs? If you are deploying cloud-init enabled Linux VMs you can use custom_data_file to specify a script that runs at deployment time. The script is executed via cloud-int.

You could script something that uses custom script (Windows or Linux) by using a shell post processors. The post processor executes an az cli script that install the custom script extension.

The Packer community may be a good resource too.

yeah, in this specific case it's for Windows VMs.

I guess something that acts like the userdata property in the aws builder would be great.
A post processor won't help here, right? I need this to run before any of the packer provisioners run.

Thanks for clarifying. How about the shell local provisioner? I think this will allow the ordering you want

that might do the trick, yeah.
Worth a test, but I think I'd rather see this implemented in the builder.

like in AWS - user_data_file can i use custom_data_file to include powershell on boot ?

bump - lots of people have been having troubles with the remote provisioners on Windows. I'd like the options to configure the VMs myself by running a script locally. I want the user_data_file behaviour but for Azure and for Windows machines

@paulmey Based on some reading and googling, I'm under the impression that what's being asked for here (custom_data_file that can run against windows vms) isn't actually an option in Azure. Is that correct? If I'm wrong, can you point me to some docs for the tool so I can try to implement this feature?

Hello @SwampDragons When I try to provision a Windows 2019 server using the Azure portal, I see an option under the "Advanced" tab to provide custom scripts upon a first boot of the Windows VM. I also see some mention of Wndows VM's having this feature at: https://docs.microsoft.com/en-us/azure/virtual-machines/custom-data. However, the Microsoft link does not make it very clear if custom scripts are permitted during a Windows VM provisioning(there is some mention of Windows VM's though). Hence, i believe the ARM templates themselves support this for Windows VM's and we did like to have this functionality for Windows VM's as well.

Currently, if i did like to execute scripts even before the provisioning phase is started, how do i do that with Windows VMs?

Regards,
Kiran Hegde

From your link:

Custom data is placed in %SYSTEMDRIVE%\AzureData\CustomData.bin as a binary file, but it is not processed. If you wish to process this file, you will need to build a custom image, and write code to process the CustomData.bin.

So you need to create a custom image and write code to process the CustomData bin, BEFORE Packer is run. Packer cannot do this for you.

Once you have a custom image that will process the data, you can use the custom_data field as documented here: https://www.packer.io/docs/builders/azure/arm#custom_data_file

I'm closing this issue because Packer can't generate images that will process the custom data, but does already provide the custom data to the image. So the part of this we can handle, is already handled. If anyone decides to write a tool that processes the custom data sent to windows VMs, please let us know and we'll link it in our docs.

Hello,

I had the same kind of issue when I tried to build a Windows image using our already existing provisioning stack. We were using the Azure DSC VM Extension, and I wanted to be able to reuse most of the setup. I created a small Packer provisioner to do that.

I just got notified by Github that this issue was closed, and so I figured out that I should quickly open-source our small provisioner.

Disclaimer: I probably won't maintain it, because we don't use it anymore (it was still used 1 month ago). But hopefully, you can find what you are looking for.

The code is really simple and should work with any Azure VM Extension. It may need to be adapted a little bit for the latest version of Packer (due to HCL2).

Repository: https://github.com/dethi/packer-provisioner-azurerm-vm-extension
An example using DSC Extension: https://github.com/dethi/packer-provisioner-azurerm-vm-extension/blob/master/example/packer_example.json#L56-L62

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mwhooker picture mwhooker  ยท  3Comments

jesse-c picture jesse-c  ยท  3Comments

craigsimon picture craigsimon  ยท  3Comments

s4mur4i picture s4mur4i  ยท  3Comments

frezbo picture frezbo  ยท  3Comments