0
votes

How can we pass parameters to child runbook written in python using Start-AzureRmAutomationRunbook.

Start-AzureRmAutomationRunbook accepts -Parameter option for named parameters (works great with child runbooks written in PowerShell). But since python supports positional parameters (args), I am not able to use -Parameter option.

By the way, my python runbook runs on a hybrid worker, so, I am not sure how can we use inline execution, because I need to pass RunOn option (Hybrid Runbook Worker Group).

1
Have you tried checking sys.argv to see if it dumps the values there? - Ryan McVicar
I cannot use position based parameters in Start-AzureRmAutomationRunbook cmdlet, so I would not be able to check sys.argv. BTW, Start-AzureRmAutomationRunbook works great for python runbooks with no parameters. - Ajay Kumar

1 Answers

0
votes

Unfortunately the -Parameters option doesn't work for Python runbooks. This is a bug and I have filed it (https://github.com/Azure/azure-powershell/issues/5313).

You CAN use the -Parameters option of Start-AutomationRunbook from inside another runbook.

So, as a workaround, you can create a PowerShell runbook that looks like this:

Param(
    [parameter(Mandatory=$true)] [string]$runbook,
    [string]$args)

Start-AutomationRunbook -Name $runbook -Parameters @{ "args" = $args }

Then you can call that runbook from the Start-AzureRmAutomationRunbook cmdlet (assuming a Python runbook named "HelloWorldPy"):

Start-AzureRmAutomationRunbook -ResourceGroupName resourceGroupName -AutomationAccountName automationAccountName -Name Start-PythonRunbook -Parameters  @{ "runbook" = "HelloWorldPy"; "args" = "arg1 arg2 arg3" }