我想在一个自动化帐户上创建一个Runbook,其中一个小工具已经通过手臂连接到它

时间:2018-11-16 16:01:22

标签: azure automation azure-runbook

到目前为止,到目前为止,我想使用我的AR​​M模板创建一个带有运行手册和shedule的自动化帐户。但是,如果我想通过模板将我的小腿连接到我的Runbook,我似乎找不到找到这种方法的可行方法。

第一次尝试(工作):创建带有运行手册和小棚的自动化帐户

"variables": {
    "name": "StartAllVM",
    "url": "https://gallery.technet.microsoft.com/scriptcenter/Start-Azure-V2-VMs-6352312e/file/147007/1/Start-AzureV2VMs.ps1",
    "version": "1.0.0.0",
    "type": "PowerShell",
    "description": "This PowerShell script runbook connects to Azure and starts all VMs in an Azure subscription or cloud service"
},
"resources": [
    {
        "name": "AutomationDev",
        "type": "Microsoft.Automation/automationAccounts",
        "apiVersion": "2015-10-31",
        "properties": {
            "sku": {
                "name": "Free"
            }
        },
        "location": "[parameters('location')]",
        "tags": {},
        "resources": [
            {
                "name": "[variables('name')]",
                "type": "runbooks",
                "apiVersion": "2015-01-01-preview",
                "location": "[resourceGroup().location]",
                "dependsOn": [
                    "[concat('Microsoft.Automation/automationAccounts/', 'AutomationDev')]"
                ],
                "properties": {
                    "runbookType": "PowerShell",
                    "logProgress": false,
                    "logVerbose": true,
                    "publishContentLink": {
                        "uri": "[variables('url')]",
                        "version": "[variables('version')]"
                    }
                }
            },
            {
                "comments": "",
                "type": "schedules",
                "name": "shedule1",
                "apiVersion": "2015-10-31",
                "location": "[resourceGroup().location]",
                "dependsOn": [
                    "[concat('Microsoft.Automation/automationAccounts/', 'AutomationDev')]",
                    "[variables('name')]"
                ],
                "properties": {
                    "description": "VM Patch Automation Schedule",
                    "startTime": "06:00PM",
                    "expiryTime": "",
                    "isEnabled": true,
                    "interval": 1,
                    "frequency": "Week",
                    "timeZone": "UTC",
                    "advancedSchedule": {
                        "weekDays": [
                            "Monday"
                        ]
                    }
                }
            }
        ]
    }
]

第二次尝试在这里我没有收到错误,但屏幕未连接到运行本 -我将"runbook": "variables('name')",添加到了框架属性

第三次尝试(这里我得到的错误配置不正确

我试图像这样在runbook的资源值中添加shedule块

 {
                "name": "[variables('name')]",
                "type": "runbooks",
                "apiVersion": "2015-01-01-preview",
                "location": "[resourceGroup().location]",
                "dependsOn": [
                    "[concat('Microsoft.Automation/automationAccounts/', 'AutomationDev')]"
                ],
                "properties": {
                    "runbookType": "PowerShell",
                    "logProgress": false,
                    "logVerbose": true,
                    "publishContentLink": {
                        "uri": "[variables('url')]",
                        "version": "[variables('version')]"
                    }
                },
                "resources": [
                    {
                        "comments": "",
                        "type": "schedules",
                        "name": "shedule1",
                        "apiVersion": "2015-10-31",
                        "location": "[resourceGroup().location]",
                        "dependsOn": [
                            "[concat('Microsoft.Automation/automationAccounts/', 'AutomationDev' , variables('name'))]",

                        ],
                        "properties": {
                            "description": "VM Patch Automation Schedule",
                            "runbook": "variables('name')",
                            "startTime": "06:00PM",
                            "expiryTime": "",
                            "isEnabled": true,
                            "interval": 1,
                            "frequency": "Week",
                            "timeZone": "UTC",
                            "advancedSchedule": {
                                "weekDays": [
                                    "Monday"
                                ]
                            }
                        }
                    }
                ]
            }

我得到的错误如下:

New-AzureRmResourceGroupDeployment : 16:43:44 - Error: Code=InvalidTemplate; Message=Deployment template validation fai
led: 'The resource '/subscriptions/xxxxxxxx/resourceGroups/xxxx/providers/Microsoft.Automa
tion/automationAccounts/AutomationDev/runbooks/StartAllVM/schedules/shedule1' at line '54' and column '17' doesn't depe
nd on parent resource '/subscriptions/xxxxxxxx/resourceGroups/xxx/providers/Microsoft.Aut
omation/automationAccounts/AutomationDev/runbooks/StartAllVM'. Please add dependency explicitly using the 'dependsOn' s
yntax. Please see https://aka.ms/arm-template/#resources for usage details.'.

我不知道哪个选项是正确的,我认为我的第三次尝试是向运行本添加书目的正确方法,但是我似乎找不到正确的方法来使用正确的方法

[编辑]

就像提到的答案一样,我对结构的依赖也不佳,在更改此选项后,我不断出现以下错误。我现在正在寻找解决方案的时间,但似乎找不到他们所提到的缺少的资源 我使用以下内容取决于:

"[resourceId('Microsoft.Automation/automationAccounts/runbooks', 'AutomationDev' , variables('name'))]"

并收到此错误。

New-AzureRmResourceGroupDeployment : 9:03:47 - Resource Microsoft.Automation/automationAccounts/runbooks/schedules 'AutomationDev/StartAllVM/shedule1' 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#cont
ent{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</head>\r\n<body>\r\n<div id=\"header\"><h1>Server Error</h1></div>\r\n<div id=\"content\">\r\n <div class=\"con
tent-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"
  }

3 个答案:

答案 0 :(得分:1)

您所依赖的应该是:

for(k in 5:2){ 
    for(i in 1:(k-1)){ 
        X_new[k,i] <- X[[i]]
    }
}

答案 1 :(得分:1)

或者,您可以使用resourceId()函数,该函数的可读性更高:

"dependsOn": [
    "[resourceId('Microsoft.Automation/automationAccounts/runbooks', 'AutomationDev' , variables('name'))]",
]

使用resourceId,您还可以轻松地为其他订阅\资源组中的资源构造resourceId。

resourceId([subscriptionId], [resourceGroupName], resourceType, resourceName1, [resourceName2]...)

https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions-resource#resourceid

答案 2 :(得分:0)

我知道这个问题是在不久前问到的,但是我只是想出了如何自己解决这个问题,并认为我会发帖以防它可以帮助其他人:

在模板内添加时间表块将创建时间表,但不会将其连接到Runbook。要将两者联系在一起,您还必须创建一个工作时间表

我要解决此问题的步骤如下:

1。将Runbook块添加为自动化帐户的子资源

2。将计划块添加为自动化帐户的子资源(不是作为运行手册的子资源-这是引发最后一个错误的原因)

3。将作业计划块添加为自动化帐户的子资源,并传入运行手册的名称​​和计划的名称:

    {
      "name": "string",
      "type": "Microsoft.Automation/automationAccounts/jobSchedules",
      "apiVersion": "2015-10-31",
      "properties": {
        "schedule": {
          "name": "string"
        },
        "runbook": {
          "name": "string"
        }
      }
    }

显然,您可能需要多花一点时间才能使它们正常工作,但这是我采取的一般步骤:)

-注意-不要忘记在必要时添加依赖项(例如,工作计划将取决于运行手册和已存在的计划)

参考文献: