I'd like to execute a custom .ps1 script as soon as my servers are deployed. All Azure docs and examples describes how to install something with DSC (like natively supported IIS), but how do I execute PowerShell script with ARM template, instead of stating configuration?
Azure RM Template. Execute .ps1 script after deployment is complete
azure
Related Solutions
I tested in my lab and I get the same result as you. According to this link and this link on GitHub. This is a known limitation in the platform where a dynamic public IP address doesn't resolve itself until the VM is up and running. There are two options to workaround:
Create the Public IP Address in static mode. That will ensure that Public IP address is immediately allocated. However, note that you might incur additional charges.
Change the dependency from Public IP address to the Virtual Machine that the IP address is attached to. This will ensure that the public IP address is always available.
I suggest you use a static Public IP, I tested in my lab, and it works for me.
"pubIpAddrType": "Static",
Change the vaule from Dynamic
to Static
.
Azure automation scripts run either on the Azure Automation servers in Azure, or on a local machine if you use a Hybrid worker. Using a Hybrid worker isn't going to solve your problem here, as you still have to call Azure automation to run the script, it just happens to run on the local machine.
For what you are trying to do you have a few options:
- Use Azure Automation, have hte production server call it to run the script. This can be done through a webhook that can trigger the automation script.
- Run the PowerShell script directly on your production server, you would not use Azure automation at all and just run some Azure PowerShell locally on the machine when required
- Still use Azure Automation but have it poll the production server for some indication that it needs to turn on the machine. For this, you would need a hybrid worker running on your network (as normally Azure Automation would have no access to your network). You would generally not want this hybrid worker on the prod server, as if it goes down there will be nothing to trigger the DR machine.
Using Azure Automation has the benefit of providing a central location to run your scripts and the ability to securely store credentials etc. to access Azure, but you would then need something to trigger that run book.
Best Answer
you can use a custom script extension to run a PowerShell script. you will be able to call the custom script as part of your ARM Template
http://blog.fullscale180.com/azure-arm-templates-tips-and-tricks-5-custom-script-extension-workaround-i-cannot-add-another-extension-to-a-vm-to-run-a-script-on-the-last-node-of-the-cluster/