3

我的场景:

我在 github(AUri、BUri、CUri)中托管了三个运行手册(A、B 和 C)。我正在使用 ARM 模板来创建自动化帐户、凭据、三个运行手册,然后使用其中一个(运行手册 C)创建一个作业。

Runbook C 是主要的,A 和 B 在 C 内部被调用。

问题是要从 C 调用 A 和 B,它们需要首先发布。

有没有办法通过我当前的 ARM 模板直接发布它们?

一种解决方法是将我的所有代码压缩到 Runbook C 中,但我更喜欢将它们分开。

到目前为止的代码:

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
   .......
  },
  "variables": {
   ........
  },
  "resources": [
    {
   "name": "[parameters('accountName')]",
  "apiVersion": "2015-10-31",
  "type": "Microsoft.Automation/AutomationAccounts",
  "location": "westeurope",
  "properties": {
    "sku": {
      "name": "Basic"
    }
  },
  "resources": [
    {
      "apiVersion": "2015-10-31",
      "dependsOn": [
        "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]"
      ],
      "location": "westeurope",
      "name": "[variables('A')]",
      "properties": {
        "runbookType": "Script",
        "logProgress": "false",
        "logVerbose": "false",
        "description": "[variables('runbookDescription')]",
        "publishContentLink": {
          "uri": "[variables('AUri')]",
          "version": "1.0.0.0"
        }
      },
      "type": "runbooks"
    },

    {
      "apiVersion": "2015-10-31",
      "dependsOn": [
        "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]"
      ],
      "location": "westeurope",
      "name": "[variables('B')]",
      "properties": {
        "runbookType": "Script",
        "logProgress": "false",
        "logVerbose": "false",
        "description": "[variables('runbookDescription')]",
        "publishContentLink": {
          "uri": "[variables('BUri')]",
          "version": "1.0.0.0"
        }
      },
      "type": "runbooks"
    },

    {
      "apiVersion": "2015-10-31",
      "dependsOn": [
        "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]"
      ],
      "location": "westeurope",
      "name": "[variables('C')]",
      "properties": {
        "runbookType": "Script",
        "logProgress": "false",
        "logVerbose": "false",
        "description": "[variables('runbookDescription')]",
        "publishContentLink": {
          "uri": "[variables('CUri')]",
          "version": "1.0.0.0"
        }
      },
      "type": "runbooks"
    },

    {
      "name": "[parameters('credentialName')]",
      "type": "credentials",
      "apiVersion": "2015-10-31",
      "location": "westeurope",
      "dependsOn": [
        "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]"
      ],
      "tags": { },
      "properties": {
        "userName": "[parameters('userName')]",
        "password": "[parameters('password')]"
      }
    }
    //optional code that runs the runbook created, yo need unique Guid value for "name" key
    ,
    {
      "name": "Unique GUID Here",
      "type": "jobs",
      "apiVersion": "2015-10-31",
      "location": "westeurope",
      "dependsOn": [
        "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]",
        "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'), '/credentials/', parameters('credentialName'))]",
        "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'), '/runbooks/',variables('A'))]",
        "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'), '/runbooks/',variables('B'))]",
        "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'), '/runbooks/',variables('C'))]"
      ],
      "tags": {
        "key": "value"
      },
      "properties": {
        "runbook": {
          "name": "[variables('C')]"
        }
      }
    } ]
}
4

1 回答 1

1

看起来您已经通过模板正确发布了运行手册,因为您提供了publishContentLink. 您的问题很可能是您没有将 Runbook C 标记为依赖于 Runbook A 和 B,因此 C 可能在 A 和 B 之前发布,并且当前在 Azure 自动化中,每当发布 Runbook 时,它所依赖的任何子 Runbook 都必须至少先发表一次。

解决方案是使 C runbook 的 dependsOn 字段看起来像:

"dependsOn": [ "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]", "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'), '/runbooks/', variables('B'))]", "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'), '/runbooks/', variables('A'))]" ]

于 2015-12-12T21:28:11.917 回答