带有Azure Git Repo中Powershell文件的Runbook的Azure ARM模板

问题描述 投票:-1回答:1

我们正在尝试使用Powershell部署一本定期查询Log Analytics的运行手册。我们已经在门户网站上运行了它,现在我们正在尝试构建一个ARM模板,以便将来部署到其他环境。我们在同一个Azure Devops Git存储库中拥有我们的ARM(json)模板和PS1文件,我们甚至尝试在模板中对PS1文件的路径进行硬编码,但它不起作用。有人可以在这里为我们做错什么吗?以下是ARM模板:-

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "automationAccountName": {
        "type": "string",
        "defaultValue": "Automation-XXX-INFRA-MONITORING",
        "metadata": {
            "description": "Automation Account"
        }
    },
    "automationRegion": {
        "defaultValue": "eastus2",
        "type": "string",
        "allowedValues": [
            "westeurope",
            "southeastasia",
            "eastus2",
            "southcentralus",
            "japaneast",
            "northeurope",
            "canadacentral",
            "australiasoutheast",
            "centralindia",
            "westcentralus"
        ],
        "metadata": {
            "description": "Specify the region for your automation account"
        }
    },
    "_artifactsLocation": {
        "type": "string",
        "defaultValue": "https://ABCD.visualstudio.com/3Pager/_git/Infrastructure?path=%2FAzure.Infra%2FAppInsights%2FMonthOverMonthTrendAnalysisReport.ps1&version=GBmaster",
        "metadata": {
            "description": "URI to artifacts location"
        }
    },
    "_artifactsLocation1": {
        "type": "string",
        "defaultValue": "https://ABCD.visualstudio.com/3Pager/_git/Infrastructure?path=%2FAzure.Infra%2FAppInsights%2FMonthOverMonthTrendAnalysisReport.ps1&version=GBmaster",
        "metadata": {
            "description": "URI to artifacts location"
        }
    }
},
"variables": {
    "asrScripts": {
        "runbooks": [
            {
                "name": "Test_Runbook",
                "url": "[parameters('_artifactsLocation')]",
                "version": "1.0.0.0",
                "type": "PowerShell",
                "description": "Runbook for month over month trend analysis report"
            }
        ]
      }
},
 "resources": [

    {
        "apiVersion": "2015-10-31",
        "type": "Microsoft.Automation/automationAccounts/runbooks",
        "name": "[concat(parameters('automationAccountName'), '/', variables('asrScripts').runbooks[copyIndex()].Name)]",
        "location": "[parameters('automationRegion')]", 
        "copy": {
            "name": "runbooksLoop",
            "count": "[length(variables('asrScripts').runbooks)]"
        },
        "properties": {
            "description": "[variables('asrScripts').runbooks[copyIndex()].description]",
            "runbookType": "[variables('asrScripts').runbooks[copyIndex()].type]",
            "logProgress": false,
            "logVerbose": true,
             "publishContentLink": { 
                 "uri":"[parameters('_artifactsLocation1')]",
                 "version": "[variables('asrScripts').runbooks[copyIndex()].version]"                  } 

        }
    }
],
"outputs": {}

}

azure-devops azure-resource-manager arm-template
1个回答
1
投票

您正在向URI发送URI,告诉它在哪里可以找到运行手册。创建AutomationAccount / runbooks资源类型时,它将对publishContentLink.url进行GET调用,以便从URI中获取内容。如果Azure无法访问该URI(大概是无法公开访问您的visualstudio.com URI),则它将无法访问运行手册内容,并且部署将失败。

解决方案是确保publishContentLink URI可被Azure自动化服务访问。您可以通过以下两种方式执行此操作:

  1. 将内容放入可公开访问的URI,例如Github或公共Blob存储容器中。
  2. 为内容创建SAS令牌。 https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-tutorial-secure-artifacts显示了如何使用Azure存储或通过https://xebia.com/blog/setting-up-vsts-with-arm-templates/使用VSTS进行存储的示例。
© www.soinside.com 2019 - 2024. All rights reserved.