Loading...

Azure Automation modular runbooks: calling child runbook from a main runbook

Reply A+ A-


In this post I will show you how to call child runbook from a main runbook meaning creating modular runbook in Azure Automation.


Context

You have a script (runbook) in Azure Automation.

It uses Graph API to get data from many devices meaning that it may consume a large amount of data.

Runbook may fail with the following error: System.OutOfMemoryException error.

This  error in Azure Automation runbook is caused by a memory overload while reading or processing an excessively large volume of data.


The main runbook

Authenticating

The main runbook will be used to call a child runbook.

The first step is to authenticate.

For that we will use a managed identity.

The managed identity is applied on the automation account directlty.

Once you configured a managed identity, a new account is created in Entra ID, a new enterprise application.

This account will be used to authenticate without providing credentials.

Authenticating through a runbook can be achieved through this command:


Calling child runbook

The second step is to call the child runbook.

To call a runbook we will the the Start-AzAutomationRunbook cmdlet.

We will pass the following parameters:

- AutomationAccountName: automation account

- ResourceGroupName: resource group

- Name: runbook to call

- Parameters: parameters to add


In the following example I will call a child runbook and add the following parameter: SystandDeploy.


The child runbook

In the child runbook I will just add the parameter passed by the main runbook.

For that I will add the following code:


Calling child runbook in action

Now let's call the child runbook.

Here is the main runbook I used:


Here is the child runbook I used:


Here is the code of the main runbook:

On the main runbook,  click on the Start button:


The runbook is starting:


Then, we can see the Child runbook is called:


The output displays what we added as parameter:



What's next ?

In the next post I will show how to call as many instances of a child runbook we want by adding a logic to wait if there are too much execution.


Start-AzAutomationRunbook 2985653272907774057

Enregistrer un commentaire

Accueil item

Award

Sponsors

Learn KQL in one month

You want to support me ?

Mes articles en français

Books in French


Stats