How do i invoke a Runbook after a VM is created from the portal? I do not see any way to set the trigger and assign a Runbook to it?
If this is not possible, how do i achieve this?
There is currently no direct way to say a runbook should be started after a VM is created, from the portal. This can be done if deploying the VM via an ARM template though, as the ARM template can declare that a runbook job should be started after the VM has been created.
In terms of a portal-based way, you could create a runbook and have it run on a schedule, polling for new VMs to take some action against, as BenV says. Or you could create a webhook for the runbook you want to start, and use the Custom Script Extension in your VM to start that webhook. Since the custom script will run once the VM is created, the runbook will be started after the VM is created.
Related
I would like to run some custom cleanup script in powershell or Az CLI to cleanup some resources that get created in a resource group but do not get cleaned up automatically when the resource group is deleted.
I can run a custom script manually and then delete the resource group, but I was wondering if there was a way to have it setup so a script is called automatically when the resource group is deleted from the Portal from example.
Have a look at Azure Automation:
Azure Automation delivers a cloud-based automation and configuration service that supports consistent management across your Azure and non-Azure environments. It comprises process automation, configuration management, update management, shared capabilities, and heterogeneous features. Automation gives you complete control during deployment, operations, and decommissioning of workloads and resources.
Source: An introduction to Azure Automation
You can use an Event Grid event as the trigger to run your automation runbook.
I have a working Azure Automation Hybrid Runbook Worker that is successfully executing runbooks. From one such Hybrid runbook I need to pass a result on to another runbook that must run on Azure, not on the Hybrid Worker.
After doing some research it seems that I have to use the Start-AzAutomationRunbook cmdlet to start the Azure runbook - which requires a Connect-AzAccount before, which means additional authentication:
To use Start-AzAutomationRunbook, the script must authenticate to your
Azure subscription.
But this seems overly complicated. Is there a less complex way to chain Azure and Hybrid runbooks? Without having to explicitly authenticate again? Overall, the runbooks are located in the same Automation account right next to each other.
I have an automation account in azure that starts and stops some VMs. I have no issue stopping the VMs, but It can not start them. I assume that this is related to recent password change that we did. I know that we need to change something in Azure PowerShell, but I don't know what to change and how to access it.
In what way you start and stop VMs through Azure Automation account? Is it using Start Stop VM solution or using a custom runbook with Start-AzVM and Stop-AzVM cmdlets.
If its using Start Stop VM Solution then see if this troubleshooting guide helps to resolve your issue.
If its using custom runbook then it would be easy to diagnose the issue if you can provide your runbook.
We are using an Azure Classic Virtual Machine!! It does not show 'AutoShutDown' Blade. Is this feature not available for Classic VM? When I searched, there is also an option to use Runbook in Automation Account to do this. Is anyone used this with classic VM?
This feature is not available with classic vms. its 2019, you should migrate to ARM anyway. but you could use custom powershell runbook to shutdown classic vms using a schedule.
you'd need to tag the resource groups (cant tag classic resources) and invoke the runbook hourly. this would be a nice starting point. in fact it does what you ask for.
Is there any way in which I can automate stopping my VM on a Friday and starting this back up again on the Sunday evening at specified times?
I’m aware this is possible via the VM blade and DevTest labs but their only option is daily, whereas I want this only shut down in the weekends.
Any input will be greatly appreciated. Thanks
Given that you need more precise control over scheduling than is possible in the Azure VM Auto-Shutdown blade or Azure Dev-Test Labs, you can accomplish startup / shutdown on specific days via RunBooks in an Azure Automation Resource.
Create (or choose an existing) Azure Automation Account resource
In the new Automation resource, go to the Runbooks blade
Click "Browse Gallery"
Search for and import "Stop Azure V2 VMs" and "Start Azure V2 VMs" runbooks
Schedule the new runbooks to run as needed
This walkthrough shows how to setup your runbooks with a specific schedule and parameters to target your virtual machine(s).
I would recomment to you, to read this:
http://azurecorner.com/start-stop-windows-azure-vms-according-time-schedule/