Azure自动化资源模板无法找到资源

时间:2018-01-16 10:35:11

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

我创建了一个azure资源模板,该模板可以从其中一个快速入门模板中进行调整。

我希望它为azure自动化,Runbook,计划,工作和jobSchedule创建一些资源。这样做的目的是使运行脚本在工作日结束时暂停SQL数据仓库实例。

我正在尝试运行模板,但是收到一个错误,它无法创建jobSchedule,并且错误会在其中找不到资源的某些html。

模板:

{
  "$schema": "http://schemas.microsoft.org/azure/deploymentTemplate?api-version=2015-01-01-preview#",
  "contentVersion": "1.0",
  "parameters": {
    "accountName": {
      "type": "string",
      "metadata": {
        "description": "The name of the Azure Automation account to deploy to."
      }
    },
    "credentialName": {
      "type": "string",
      "defaultValue": "SqlAutomationCredentials",
      "metadata": {
        "description": "SqlAutomationCredentials is the name of the Automation credential used in this runbook. This credential allows you to authenticate to Azure. "
      }
    },
    "userName": {
      "type": "string",
      "metadata": {
        "description": "The username for the Azure Automation credential."
      }
    },
    "password": {
      "type": "securestring",
      "metadata": {
        "description": "The password for the Azure Automation credential."
      }
    },
    "jobId": {
      "type": "string",
      "metadata": {
        "description": "The GUID for the runbook job to be started."
      }
    },
    "ingestSchedulerGuid": {
      "type": "string",
      "metadata": {
        "description": "The GUID for schedule"
      }
    },
    "iso8601StartTime": {
      "type": "string",
      "metadata": {
        "description": "ISO8601 string for the start of the schedule, has to be in the future because Azure validation says so"
      }
    },
    "subscriptionName": {
      "type": "string"
    }
  },
  "variables": {
    "runbookName": "PauseResourcesIfRunning",
    "scriptUri": "https://gist.githubusercontent.com/CBurbidge/56222bdaf181b0cca6b5f2c1e6862b1c/raw/7cf457b1eb3f5a64223cc6d3080679a0759cd731/PauseResourcesIfRunning.ps1",
    "runbookDescription": "Loops through rm resources and pauses ones which can be paused.",
    "sku": "Free",
    "scheduleLocation": "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'), '/schedules/sixPmWeekDaysSchedule','-',parameters('ingestSchedulerGuid'))]",
    "scheduleName": "[concat(                                            parameters('accountName'),           '/sixPmWeekDaysSchedule','-',parameters('ingestSchedulerGuid'))]",
    "endOfWorkDayScheduleName": "[concat(parameters('accountName'), '/sixPmWeekDaysSchedule','-',parameters('ingestSchedulerGuid'))]",
    "endOfWorkDayScheduleNameEnd": "[concat('sixPmWeekDaysSchedule','-',parameters('ingestSchedulerGuid'))]",
    "pauseResourcesRunbookName": "PauseResourcesIfRunning",
    "jobScheduleName": "[concat(parameters('accountName'), '/pauseResourcesAtEndOfWorkDay', '-', parameters('ingestSchedulerGuid'))]",
    "jobScheduleLocation": "[concat(parameters('accountName'), '/pauseResourcesAtEndOfWorkDay', '-', parameters('ingestSchedulerGuid'))]"
  },
  "resources": [
    {
      "name": "[parameters('accountName')]",
      "type": "Microsoft.Automation/automationAccounts",
      "apiVersion": "2015-01-01-preview",
      "location": "[resourceGroup().location]",
      "dependsOn": [],
      "tags": {},
      "properties": {
        "sku": {
          "name": "[variables('sku')]"
        }
      },
      "resources": [
        {
          "name": "[variables('pauseResourcesRunbookName')]",
          "type": "runbooks",
          "apiVersion": "2015-01-01-preview",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]"
          ],
          "tags": {},
          "properties": {
            "runbookType": "Script",
            "logProgress": "false",
            "logVerbose": "false",
            "description": "[variables('runbookDescription')]",
            "publishContentLink": {
              "uri": "[variables('scriptUri')]",
              "version": "1.0.0.0"
            }
          }
        },
        {
          "name": "[parameters('credentialName')]",
          "type": "credentials",
          "apiVersion": "2015-01-01-preview",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]"
          ],
          "tags": {},
          "properties": {
            "userName": "[parameters('userName')]",
            "password": "[parameters('password')]"
          }
        },
        {
          "name": "[variables('endOfWorkDayScheduleName')]",
          "type": "microsoft.automation/automationAccounts/schedules",
          "apiVersion": "2015-10-31",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[parameters('accountName')]",
            "[variables('pauseResourcesRunbookName')]"
          ],
          "tags": {},
          "properties": {
            "description": "6pm work days",
            "startTime": "[parameters('iso8601StartTime')]",
            "isEnabled": "true",
            "interval": "1",
            "frequency": "day",
            "advancedSchedule": {
              "weekDays": [
                "monday",
                "tuesday",
                "wednesday",
                "thursday",
                "friday"
              ]
            }
          }
        },
        {
          "name": "[variables('jobScheduleName')]",
          "type": "microsoft.automation/automationAccounts/jobSchedules",
          "apiVersion": "2015-10-31",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[parameters('accountName')]",
            "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'), '/runbooks/', variables('pauseResourcesRunbookName'))]",
            "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'), '/schedules/', variables('endOfWorkDayScheduleNameEnd'))]"
          ],
          "tags": {},
          "properties": {
            "schedule": {
              "name": "[variables('endOfWorkDayScheduleNameEnd')]"
            },
            "runbook": {
              "name": "[variables('pauseResourcesRunbookName')]"
            },
            "parameters": {
              "credentialName": {
                "value": "[parameters('credentialName')]"
              },
              "subscriptionName": {
                "value": "[parameters('subscriptionName')]"
              }
            }
          }
        },
        {
          "name": "[parameters('jobId')]",
          "type": "jobs",
          "apiVersion": "2015-01-01-preview",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'))]",
            "[concat('Microsoft.Automation/automationAccounts/', parameters('accountName'), '/runbooks/',variables('pauseResourcesRunbookName'))]"
          ],
          "tags": {
            "key": "value"
          },
          "properties": {
            "runbook": {
              "name": "[variables('pauseResourcesRunbookName')]"
            }
          }
        }
      ]
    }
  ],
  "outputs": {}
}

错误是

New-AzureRmResourceGroupDeployment : 10:16:32 - Resource microsoft.automation/automationAccounts/jobSchedules'SqlAutomation/pauseResourcesAtEndOfWorkDay-1a8de9a0-8780-47c0-9fdb-4888790f79a3' failed with message
'{
  "error": {
    "code": "BadRequest",
    "message": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n<html
xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=iso-8859-1\"/>\r\n<title>404 - File or directory not found.</title>\r\n<style
type=\"text/css\">\r\n<!--\r\nbody{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica,
sans-serif;background:#EEEEEE;}\r\nfieldset{padding:0 15px 10px 15px;}
\r\nh1{font-size:2.4em;margin:0;color:#FFF;}\r\nh2{font-size:1.7em;margin:0;color:#CC0000;}
\r\nh3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} \r\n#header{width:96%;margin:0 0 0 0;padding:6px 2%
6px 2%;font-family:\"trebuchet MS\", Verdana,
sans-serif;color:#FFF;\r\nbackground-color:#555555;}\r\n#content{margin:0 0 0 2%;position:relative;}\r\n.content
-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}\r\n-->\r\n</style>\r\n</hea
d>\r\n<body>\r\n<div id=\"header\"><h1>Server Error</h1></div>\r\n<div id=\"content\">\r\n <div
class=\"content-container\"><fieldset>\r\n  <h2>404 - File or directory not found.</h2>\r\n  <h3>The resource
you are looking for might have been removed, had its name changed, or is temporarily unavailable.</h3>\r\n
</fieldset></div>\r\n</div>\r\n</body>\r\n</html>\r\n"
  }
}'

我的理解是jobSchedule应该等待创建日程表和Runbook,因为它们是在dependsOn中指定的,因此我不确定为什么没有找到该资源。

之前我没有看到过这种类型的html混合错误,之前的依赖错误已经更明显了问题是什么。任何想法都表示赞赏。

2 个答案:

答案 0 :(得分:0)

我怀疑错误来自于您在jobSchedule名称中使用/的事实。删除它。

答案 1 :(得分:0)

JobSchedules&#39;名字是Guids。你应该调整你的变量&#34; jobScheduleName&#34;值得成为指导。