【问题标题】:Azure automation : Pass parameters to child runbook in pythonAzure 自动化:将参数传递给 python 中的子 Runbook
【发布时间】:2018-06-12 19:31:33
【问题描述】:

我们如何使用 Start-AzureRmAutomationRunbook 将参数传递给用 python 编写的子 Runbook。

Start-AzureRmAutomationRunbook 接受命名参数的 -Parameter 选项(适用于用 PowerShell 编写的子 Runbook)。但是由于python支持位置参数(args),我无法使用-Parameter选项。

顺便说一句,我的 python runbook 运行在一个混合工作人员上,所以,我不确定我们如何使用内联执行,因为我需要传递 RunOn 选项(混合 Runbook 工作组)。

【问题讨论】:

  • 您是否尝试过检查 sys.argv 以查看它是否将值转储到那里?
  • 我无法在 Start-AzureRmAutomationRunbook cmdlet 中使用基于位置的参数,因此我无法检查 sys.argv。顺便说一句,Start-AzureRmAutomationRunbook 适用于没有参数的 python Runbook。

标签: python powershell azure azure-automation


【解决方案1】:

很遗憾,-Parameters 选项不适用于 Python Runbook。这是一个错误,我已提交 (https://github.com/Azure/azure-powershell/issues/5313)。

您可以在另一个 Runbook 中使用 Start-AutomationRunbook 的 -Parameters 选项。

因此,作为一种解决方法,您可以创建如下所示的 PowerShell Runbook:

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

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

然后您可以从 Start-AzureRmAutomationRunbook cmdlet 调用该 Runbook(假设 Python Runbook 名为“HelloWorldPy”):

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

【讨论】:

  • 我刚刚重读了您的问题,看来您实际上已经在尝试将 Python Runbook 作为子 Runbook 启动。如果父 Runbook 是 PowerShell Runbook,则可以只使用那里的 Start-Automation cmdlet 而不是 Start-AzureRmAutomationRunbook。并且还支持-RunOn参数。
猜你喜欢
  • 2023-04-10
  • 2020-10-30
  • 2016-06-22
  • 2021-07-27
  • 2022-12-07
  • 2019-05-17
  • 1970-01-01
  • 2021-03-21
  • 1970-01-01
相关资源
最近更新 更多