首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何防止Microsoft.Automation/automationAccounts/Compilationjobs总是在ARM部署中运行?

如何防止Microsoft.Automation/automationAccounts/Compilationjobs总是在ARM部署中运行?
EN

Stack Overflow用户
提问于 2019-02-03 22:07:00
回答 1查看 409关注 0票数 0

我的ARM模板在下面,它是嵌套在较大ARM模板中的模板。出于某种原因,DSC编译作业总是在每个部署上运行。我以为如果它以前已经运行过的话就不会运行了。我该如何控制这种行为?我试过使用"incrementNodeConfigurationBuild": "false",但它没有起作用。

代码语言:javascript
复制
 {
      "name": "WorkerNodeDscConfiguration",
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2017-05-10",
      "resourceGroup": "[parameters('automationAccountRGName')]",
      "dependsOn": [],
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.1",
          "resources": [
            {
              "apiversion": "2015-10-31",
              "location": "[reference(variables('automationAccountResourceId'), '2018-01-15','Full').location]",
              "name": "[parameters('automationAccountName')]",
              "type": "Microsoft.Automation/automationAccounts",
              "properties": {
                "sku": {
                  "name": "Basic"
                }
              },
              "tags": {},
              "resources": [
                {
                  "name": "workernode",
                  "type": "configurations",
                  "apiVersion": "2018-01-15",
                  "location": "[reference(variables('automationAccountResourceId'), '2018-01-15','Full').location]",
                  "dependsOn": [
                    "[concat('Microsoft.Automation/automationAccounts/', parameters('AutomationAccountName'))]"
                  ],
                  "properties": {
                    "state": "Published",
                    "overwrite": "false",
                    "incrementNodeConfigurationBuild": "false",
                    "Source": {
                      "Version": "1.2",
                      "type": "uri",
                      "value": "[parameters('WorkerNodeDSCConfigURL')]"
                    }
                  }
                },
                {
                  "name": "[guid(resourceGroup().id, deployment().name)]",
                  "type": "Compilationjobs",
                  "apiVersion": "2018-01-15",
                  "tags": {},
                  "dependsOn": [
                    "[concat('Microsoft.Automation/automationAccounts/', parameters('AutomationAccountName'))]",
                    "[concat('Microsoft.Automation/automationAccounts/', parameters('AutomationAccountName'),'/Configurations/workernode')]"
                  ],
                  "properties": {
                    "configuration": {
                      "name": "workernode"
                    },
                    "incrementNodeConfigurationBuild": "false",
                    "parameters": {
                      "WebServerContentURL": "[parameters('WebServerContentURL')]"
                    }
                  }
                }
              ]
            }
          ]
        }
      }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-18 10:07:35

简而言之,AFAIK您应该能够用“条件”来控制这种行为。

详细地解释一下,DSC编译作业资源总是在每个部署上运行,因为当我们使用DSC编译作业资源(即ARM模板中的Microsoft.Automation/automationAccounts/compilationjobs) )时,它在后面所做的就是点击DSC配置的“编译”按钮。

如果单击“编译”按钮,即使它已经编译了作业,也肯定会进行作业的编译。您也可以手动检查同一部件。

因此,AFAIK --这就是编译作业总是在每个部署上运行的原因。

您可以做的是,用“条件”更新您的ARM模板(有关更多信息,请参阅https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-resources#conditionhttps://learn.microsoft.com/en-us/azure/architecture/building-blocks/extending-templates/conditional-deploy),然后用下面的示例PowerShell代码包装模板,该代码将确定是否已经为特定的PowerShell配置编译作业,然后通过传递内联参数值或相应地用新的或现有的值更新参数模板文件中的条件参数来部署模板。(有关更多信息,请参见https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-deploy#pass-parameter-values)

代码语言:javascript
复制
$DscCompilationJob = Get-AzAutomationDscCompilationJob -AutomationAccountName AUTOMATIONACCOUNTNAME -ResourceGroupName RESOURCEGROUPNAME|Sort-Object -Descending -Property CreationTime|Select -First 1| Select Status
$DscCompilationJobStatus = $DscCompilationJob.Status
if ($DscCompilationJobStatus -ne "Completed"){
    $DscCompilationJobStatusInlineParameter = "new"
    New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName testgroup -TemplateFile TEMPLATEFILEPATH\demotemplate.json -exampleString $DscCompilationJobStatusInlineParameter
    #or update condition parameter in parameters template file with new value accordingly and use below command to deploy the template
    New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile TEMPLATEFILEPATH\demotemplate.json -TemplateParameterFile TEMPLATEFILEPATH\demotemplate.parameters.json
}else{
    $DscCompilationJobStatusInlineParameter = "existing"
    New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName testgroup -TemplateFile TEMPLATEFILEPATH\demotemplate.json -exampleString $DscCompilationJobStatusInlineParameter
    #or update condition parameter in parameters template file with existing value accordingly and use below command to deploy the template
    New-AzResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile TEMPLATEFILEPATH\demotemplate.json -TemplateParameterFile TEMPLATEFILEPATH\demotemplate.parameters.json
}

关于incrementNodeConfigurationBuild属性,IMHO此属性仅用于创建节点配置的新构建版本是否需要,即当增量节点配置生成设置为false时,它不会通过创建名为CONFIGNAME<2>的新节点配置来覆盖先前的现有节点配置。

希望这能帮上忙!干杯!!)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54508062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档