ARM模板创建和发布Azure Runbook

时间:2015-12-11 14:23:52

标签: azure azure-resource-manager azure-automation

我的情景:

我在github(AUri,BUri,CUri)中托管了三本Runbook(A,B和C)。我正在使用ARM模板创建自动化帐户,凭据,三个Runbook,然后使用其中一个创建作业(Runbook 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')]"
        }
      }
    } ]
}

1 个答案:

答案 0 :(得分:1)

您似乎已经通过模板正确发布了Runbook,因为您提供的是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'))]" ]