Azure App Insights状态监视器扩展无法使用ARM模板部署

Azure App Insights状态监视器扩展无法使用ARM模板部署,azure,azure-application-insights,azure-resource-manager,Azure,Azure Application Insights,Azure Resource Manager,我刚开始失败,不知道为什么;昨天天气很好。我只将appsettings和connectionstring更改为part或resources,而不是webapp,以将dependsOn向下移动。以前,该站点依赖于应用程序设置和连接字符串的依赖关系。以下是网站资源的ARM模板 { "comments": "Primary web app deployment.", "name": "[variables('webAppName')]", "type":

我刚开始失败,不知道为什么;昨天天气很好。我只将appsettings和connectionstring更改为part或resources,而不是webapp,以将dependsOn向下移动。以前,该站点依赖于应用程序设置和连接字符串的依赖关系。以下是网站资源的ARM模板

{
        "comments": "Primary web app deployment.",
        "name": "[variables('webAppName')]",
        "type": "Microsoft.Web/sites",
        "apiVersion": "2016-08-01",
        "kind": "app",
        "location": "[variables('rgLocation')]",
        "tags": {},
        "dependsOn": [
            "[resourceId('Microsoft.Web/serverfarms', variables('planName'))]"
        ],
        "properties": {
            "enabled": true,
            "hostNameSslStates": [
                {
                    "name": "[concat(variables('webAppName'), '.azurewebsites.net')]",
                    "sslState": "Disabled"
                },
                {
                    "name": "[concat(variables('webAppName'), '.scm.azurewebsites.net')]",
                    "sslState": "Disabled"
                }
            ],
            "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('planName'))]",
            "siteConfig": {
                "numberOfWorkers": 1,
                "defaultDocuments": [
                    "Default.htm",
                    "Default.html",
                    "Default.asp",
                    "index.htm",
                    "index.html",
                    "iisstart.htm",
                    "default.aspx",
                    "index.php",
                    "hostingstart.html"
                ],
                "netFrameworkVersion": "v4.6",
                "phpVersion": "",
                "pythonVersion": "",
                "nodeVersion": "",
                "linuxFxVersion": "",
                "requestTracingEnabled": false,
                "remoteDebuggingEnabled": false,
                "remoteDebuggingVersion": "VS2015",
                "httpLoggingEnabled": false,
                "logsDirectorySizeLimit": 35,
                "detailedErrorLoggingEnabled": false,
                "scmType": "None",
                "use32BitWorkerProcess": false,
                "webSocketsEnabled": false,
                "alwaysOn": true,
                "managedPipelineMode": "Integrated",
                "virtualApplications": [
                    {
                        "virtualPath": "/",
                        "physicalPath": "site\\wwwroot",
                        "preloadEnabled": false
                    }
                ],
                "autoHealEnabled": false,
                "vnetName": ""
            },
            "microService": "WebSites",
            "clientAffinityEnabled": false,
            "clientCertEnabled": false,
            "hostNamesDisabled": false
        },
        "resources": [
            {
                "name": "appsettings",
                "type": "config",
                "apiVersion":"2015-08-01",
                "dependsOn":[
                    "[resourceId('Microsoft.Web/sites', variables('webAppName'))]",
                    "[resourceId('microsoft.insights/components', variables('insightsName'))]"
                ],
                "properties": {
                    "APPINSIGHTS_INSTRUMENTATIONKEY":"[reference(resourceId('Microsoft.Insights/components', variables('insightsName')), '2015-05-01').InstrumentationKey]",
                    "UseAzureStorageEmulator": "false"
                }
            },
            {
                "name": "connectionstrings",
                "type": "config",
                "apiVersion":"2015-08-01",
                "dependsOn":[
                    "[resourceId('Microsoft.Web/sites', variables('webAppName'))]",
                    "[resourceId('Microsoft.Storage/storageAccounts', variables('genStorageName'))]",
                    "[resourceId('Microsoft.Storage/storageAccounts', variables('jobStorageName'))]"
                ],
                "properties": {
                    "AzureStorage": {
                        "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('genStorageName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('genStorageName')), '2017-06-01').keys[0].value, ';EndpointSuffix=core.windows.net')]",
                        "type": "Custom"
                    },
                    "AzureWebJobsDashboard" : {
                        "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('jobStorageName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('jobStorageName')), '2017-06-01').keys[0].value, ';EndpointSuffix=core.windows.net')]",
                        "type": "Custom"
                    },
                    "AzureWebJobsStorage" : {
                        "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('jobStorageName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('jobStorageName')), '2017-06-01').keys[0].value, ';EndpointSuffix=core.windows.net')]",
                        "type": "Custom"
                    }
                }
            },
            {
                "apiVersion":"2015-08-01",
                "name": "Microsoft.ApplicationInsights.AzureWebSites",
                "type": "siteextensions",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/Sites', variables('webAppName'))]"
                ],
                "properties": {}
            }
        ]
    }
我得到的错误是

STATUS Conflict
PROVISIONING STATE Failed
TIMESTAMP7/14/2017, 10:40:23 AM
DURATION 1 minute 46 seconds
TYPE Microsoft.Web/sites/siteextensions
RESOURCE ID /subscriptions/.../providers/Microsoft.Web/sites/.../siteextensions/Microsoft.ApplicationInsights.AzureWebSites
STATUSMESSAGE{
    "status": "Canceled",
    "error": {
        "code": "ResourceDeploymentFailure",
        "message": "The resource operation completed with terminal provisioning state 'Canceled'."
    }
}
即使有错误,它也确实正确安装了扩展。在另一次测试中,它安装了扩展,但当我打开它时,没有安装AppInsights Profiler web作业。不管怎样,我都不知道为什么会有冲突。当我在Kudu打开日志时,里面几乎什么都没有

7/14/2017 2:44:38 PM: [Verbose] Starting Application Insights installation and configuration...
7/14/2017 2:44:38 PM: [Verbose] Loading assembly from D:\home\SiteExtensions\Microsoft.ApplicationInsights.AzureWebSites\Microsoft.ApplicationInsights.WebSiteManager.dll
7/14/2017 2:44:39 PM: [Verbose] No web.config detected. The web app may be empty. Assume classic ASP.NET by default.
这就是日志的全部内容

在之前的测试中

7/13/2017 6:15:44 PM: [Verbose] Starting Application Insights installation and configuration...
7/13/2017 6:15:44 PM: [Verbose] Loading assembly from D:\home\SiteExtensions\Microsoft.ApplicationInsights.AzureWebSites\Microsoft.ApplicationInsights.WebSiteManager.dll
7/13/2017 6:15:44 PM: [Verbose] No web.config detected. The web app may be empty. Assume classic ASP.NET by default.
文件的开头相同,但有更多条目。肯定有一个web配置,应用程序正在运行,所以不确定这是怎么回事

7/13/2017 6:15:50 PM: [Verbose] Application is not instrumented with Application Insights.
7/13/2017 6:15:50 PM: [Verbose] Starting to download/install 'Microsoft.ApplicationInsights.Azure.WebSites' nuget package from D:\home\SiteExtensions\Microsoft.ApplicationInsights.AzureWebSites\appinsights...
7/13/2017 6:15:52 PM, [Verbose] Installing 'Microsoft.ApplicationInsights', version '2.3.0' ...
7/13/2017 6:15:53 PM, [Verbose] Installed 'Microsoft.ApplicationInsights', version '2.3.0'.

该应用程序肯定安装了检测工具,并使用了比安装的2.3版本更新的2.4版本。

根据您的描述,我认为已安装的siteextensions被取消的原因是更改了应用设置,web应用程序将重新启动。因此,它将取消siteextensions安装线程

部署更改web app应用程序设置后,将重新启动web app。但您的部署仍在运行安装siteextensions的线程。因此,您将面临线程取消错误

我建议您可以在web app资源的siteConfig功能期间设置appsettings。部署模板时,安装siteextensions时不会导致web应用程序重新启动

模板的某些部分可参考以下代码:

    "siteConfig": {
      "appSettings": [
        {
          "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
          "value": "[reference(resourceId('Microsoft.Insights/components', variables('webSiteName')), '2015-05-01').InstrumentationKey]"
        }
      ]
整个测试模板:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "hostingPlanName": {
      "type": "string",
      "minLength": 1
    },
    "skuName": {
      "type": "string",
      "defaultValue": "F1",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "metadata": {
        "description": "Describes plan's instance count"
      }
    }
  },
  "variables": {
    "webSiteName": "brandotestarm11"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "capacity": "[parameters('skuCapacity')]"
      },
      "properties": {
        "name": "[parameters('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2014-04-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Insights/components",
      "location": "East US",
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
      ],
      "tags": {
        "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('webSiteName'))]": "Resource",
        "displayName": "AppInsightsComponent"
      },
      "properties": {
        "applicationId": "[variables('webSiteName')]"
      }
    },
    {
      "comments": "Primary web app deployment.",
      "apiVersion": "2015-08-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "tags": {},
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
        "[resourceId('microsoft.insights/components', variables('webSiteName'))]"
      ],
      "properties": {
        "enabled": true,
        "hostNameSslStates": [
          {
            "name": "[concat(variables('webSiteName'), '.azurewebsites.net')]",
            "sslState": "Disabled"
          },
          {
            "name": "[concat(variables('webSiteName'), '.scm.azurewebsites.net')]",
            "sslState": "Disabled"
          }
        ],
        "siteConfig": {
          "appSettings": [
            {
              "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
              "value": "[reference(resourceId('Microsoft.Insights/components', variables('webSiteName')), '2015-05-01').InstrumentationKey]"
            }
          ],
          "numberOfWorkers": 1,
          "defaultDocuments": [
            "Default.htm",
            "Default.html",
            "Default.asp",
            "index.htm",
            "index.html",
            "iisstart.htm",
            "default.aspx",
            "index.php",
            "hostingstart.html"
          ],
          "netFrameworkVersion": "v4.6",
          "phpVersion": "",
          "pythonVersion": "",
          "nodeVersion": "",
          "linuxFxVersion": "",
          "requestTracingEnabled": false,
          "remoteDebuggingEnabled": false,
          "remoteDebuggingVersion": "VS2015",
          "httpLoggingEnabled": false,
          "logsDirectorySizeLimit": 35,
          "detailedErrorLoggingEnabled": false,
          "scmType": "None",
          "use32BitWorkerProcess": false,
          "webSocketsEnabled": false,
          "alwaysOn": true,
          "managedPipelineMode": "Integrated",
          "virtualApplications": [
            {
              "virtualPath": "/",
              "physicalPath": "site\\wwwroot",
              "preloadEnabled": false
            }
          ],
          "autoHealEnabled": false,
          "vnetName": ""
        },
        "microService": "WebSites",
        "clientAffinityEnabled": false,
        "clientCertEnabled": false,
        "hostNamesDisabled": false,
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
      },
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "Microsoft.ApplicationInsights.AzureWebSites",
          "type": "siteextensions",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {}

        }
      ]
    }
  ]
}
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "hostingPlanName": {
      "type": "string",
      "minLength": 1
    },
    "skuName": {
      "type": "string",
      "defaultValue": "F1",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "metadata": {
        "description": "Describes plan's instance count"
      }
    }
  },
  "variables": {
    "webSiteName": "brandotestarmfor"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "capacity": "[parameters('skuCapacity')]"
      },
      "properties": {
        "name": "[parameters('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "tags": {
        "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
        "displayName": "Website"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
      ],
      "properties": {
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]",
        "siteConfig": {
          "numberOfWorkers": 1,
          "defaultDocuments": [
            "Default.htm",
            "Default.html",
            "Default.asp",
            "index.htm",
            "index.html",
            "iisstart.htm",
            "default.aspx",
            "index.php",
            "hostingstart.html"
          ],
          "netFrameworkVersion": "v4.6",
          "phpVersion": "",
          "pythonVersion": "",
          "nodeVersion": "",
          "linuxFxVersion": "",
          "requestTracingEnabled": false,
          "remoteDebuggingEnabled": false,
          "remoteDebuggingVersion": "VS2015",
          "httpLoggingEnabled": false,
          "logsDirectorySizeLimit": 35,
          "detailedErrorLoggingEnabled": false,
          "scmType": "None",
          "use32BitWorkerProcess": false,
          "webSocketsEnabled": false,
          "alwaysOn": true,
          "managedPipelineMode": "Integrated",
          "virtualApplications": [
            {
              "virtualPath": "/",
              "physicalPath": "site\\wwwroot",
              "preloadEnabled": false
            }
          ],
          "autoHealEnabled": false,
          "vnetName": ""
        },
        "clientAffinityEnabled": false,
        "clientCertEnabled": false,
        "hostNamesDisabled": false
      },
      "resources": [
        {
          "name": "appsettings",
          "type": "config",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', variables('webSiteName'))]",
            "[resourceId('microsoft.insights/components', variables('webSiteName'))]",
            "Microsoft.ApplicationInsights.AzureWebSites"
          ],
          "properties": {
            "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('Microsoft.Insights/components', variables('webSiteName')), '2015-05-01').InstrumentationKey]",
            "UseAzureStorageEmulator": "false"
          }
        },
        {
          "apiVersion": "2015-08-01",
          "name": "Microsoft.ApplicationInsights.AzureWebSites",
          "type": "siteextensions",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {}
        }
      ]
    },
    {
      "apiVersion": "2014-04-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Insights/components",
      "location": "East US",
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites/', variables('webSiteName'))]"
      ],
      "tags": {
        "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('webSiteName'))]": "Resource",
        "displayName": "AppInsightsComponent"
      },
      "properties": {
        "applicationId": "[variables('webSiteName')]"
      }
    }
  ]
}
结果是:


更新:

我建议您可以先安装网站扩展,然后更改应用程序设置

在web应用程序配置资源中,您可以根据web站点扩展设置其属性

因此,模板将首先安装扩展,然后更改appsetting以使web应用重新启动。因此,您可以完整地安装扩展

更多详细信息,请参考以下模板:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "hostingPlanName": {
      "type": "string",
      "minLength": 1
    },
    "skuName": {
      "type": "string",
      "defaultValue": "F1",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "metadata": {
        "description": "Describes plan's instance count"
      }
    }
  },
  "variables": {
    "webSiteName": "brandotestarm11"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "capacity": "[parameters('skuCapacity')]"
      },
      "properties": {
        "name": "[parameters('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2014-04-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Insights/components",
      "location": "East US",
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
      ],
      "tags": {
        "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('webSiteName'))]": "Resource",
        "displayName": "AppInsightsComponent"
      },
      "properties": {
        "applicationId": "[variables('webSiteName')]"
      }
    },
    {
      "comments": "Primary web app deployment.",
      "apiVersion": "2015-08-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "tags": {},
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
        "[resourceId('microsoft.insights/components', variables('webSiteName'))]"
      ],
      "properties": {
        "enabled": true,
        "hostNameSslStates": [
          {
            "name": "[concat(variables('webSiteName'), '.azurewebsites.net')]",
            "sslState": "Disabled"
          },
          {
            "name": "[concat(variables('webSiteName'), '.scm.azurewebsites.net')]",
            "sslState": "Disabled"
          }
        ],
        "siteConfig": {
          "appSettings": [
            {
              "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
              "value": "[reference(resourceId('Microsoft.Insights/components', variables('webSiteName')), '2015-05-01').InstrumentationKey]"
            }
          ],
          "numberOfWorkers": 1,
          "defaultDocuments": [
            "Default.htm",
            "Default.html",
            "Default.asp",
            "index.htm",
            "index.html",
            "iisstart.htm",
            "default.aspx",
            "index.php",
            "hostingstart.html"
          ],
          "netFrameworkVersion": "v4.6",
          "phpVersion": "",
          "pythonVersion": "",
          "nodeVersion": "",
          "linuxFxVersion": "",
          "requestTracingEnabled": false,
          "remoteDebuggingEnabled": false,
          "remoteDebuggingVersion": "VS2015",
          "httpLoggingEnabled": false,
          "logsDirectorySizeLimit": 35,
          "detailedErrorLoggingEnabled": false,
          "scmType": "None",
          "use32BitWorkerProcess": false,
          "webSocketsEnabled": false,
          "alwaysOn": true,
          "managedPipelineMode": "Integrated",
          "virtualApplications": [
            {
              "virtualPath": "/",
              "physicalPath": "site\\wwwroot",
              "preloadEnabled": false
            }
          ],
          "autoHealEnabled": false,
          "vnetName": ""
        },
        "microService": "WebSites",
        "clientAffinityEnabled": false,
        "clientCertEnabled": false,
        "hostNamesDisabled": false,
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
      },
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "Microsoft.ApplicationInsights.AzureWebSites",
          "type": "siteextensions",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {}

        }
      ]
    }
  ]
}
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "hostingPlanName": {
      "type": "string",
      "minLength": 1
    },
    "skuName": {
      "type": "string",
      "defaultValue": "F1",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "metadata": {
        "description": "Describes plan's instance count"
      }
    }
  },
  "variables": {
    "webSiteName": "brandotestarmfor"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "capacity": "[parameters('skuCapacity')]"
      },
      "properties": {
        "name": "[parameters('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "tags": {
        "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
        "displayName": "Website"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
      ],
      "properties": {
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]",
        "siteConfig": {
          "numberOfWorkers": 1,
          "defaultDocuments": [
            "Default.htm",
            "Default.html",
            "Default.asp",
            "index.htm",
            "index.html",
            "iisstart.htm",
            "default.aspx",
            "index.php",
            "hostingstart.html"
          ],
          "netFrameworkVersion": "v4.6",
          "phpVersion": "",
          "pythonVersion": "",
          "nodeVersion": "",
          "linuxFxVersion": "",
          "requestTracingEnabled": false,
          "remoteDebuggingEnabled": false,
          "remoteDebuggingVersion": "VS2015",
          "httpLoggingEnabled": false,
          "logsDirectorySizeLimit": 35,
          "detailedErrorLoggingEnabled": false,
          "scmType": "None",
          "use32BitWorkerProcess": false,
          "webSocketsEnabled": false,
          "alwaysOn": true,
          "managedPipelineMode": "Integrated",
          "virtualApplications": [
            {
              "virtualPath": "/",
              "physicalPath": "site\\wwwroot",
              "preloadEnabled": false
            }
          ],
          "autoHealEnabled": false,
          "vnetName": ""
        },
        "clientAffinityEnabled": false,
        "clientCertEnabled": false,
        "hostNamesDisabled": false
      },
      "resources": [
        {
          "name": "appsettings",
          "type": "config",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', variables('webSiteName'))]",
            "[resourceId('microsoft.insights/components', variables('webSiteName'))]",
            "Microsoft.ApplicationInsights.AzureWebSites"
          ],
          "properties": {
            "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('Microsoft.Insights/components', variables('webSiteName')), '2015-05-01').InstrumentationKey]",
            "UseAzureStorageEmulator": "false"
          }
        },
        {
          "apiVersion": "2015-08-01",
          "name": "Microsoft.ApplicationInsights.AzureWebSites",
          "type": "siteextensions",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {}
        }
      ]
    },
    {
      "apiVersion": "2014-04-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Insights/components",
      "location": "East US",
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites/', variables('webSiteName'))]"
      ],
      "tags": {
        "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('webSiteName'))]": "Resource",
        "displayName": "AppInsightsComponent"
      },
      "properties": {
        "applicationId": "[variables('webSiteName')]"
      }
    }
  ]
}
您可以将dependsOn设置为“Microsoft.ApplicationInsights.AzureWebSites”

总模板:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "hostingPlanName": {
      "type": "string",
      "minLength": 1
    },
    "skuName": {
      "type": "string",
      "defaultValue": "F1",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "metadata": {
        "description": "Describes plan's instance count"
      }
    }
  },
  "variables": {
    "webSiteName": "brandotestarm11"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "capacity": "[parameters('skuCapacity')]"
      },
      "properties": {
        "name": "[parameters('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2014-04-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Insights/components",
      "location": "East US",
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
      ],
      "tags": {
        "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('webSiteName'))]": "Resource",
        "displayName": "AppInsightsComponent"
      },
      "properties": {
        "applicationId": "[variables('webSiteName')]"
      }
    },
    {
      "comments": "Primary web app deployment.",
      "apiVersion": "2015-08-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "tags": {},
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
        "[resourceId('microsoft.insights/components', variables('webSiteName'))]"
      ],
      "properties": {
        "enabled": true,
        "hostNameSslStates": [
          {
            "name": "[concat(variables('webSiteName'), '.azurewebsites.net')]",
            "sslState": "Disabled"
          },
          {
            "name": "[concat(variables('webSiteName'), '.scm.azurewebsites.net')]",
            "sslState": "Disabled"
          }
        ],
        "siteConfig": {
          "appSettings": [
            {
              "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
              "value": "[reference(resourceId('Microsoft.Insights/components', variables('webSiteName')), '2015-05-01').InstrumentationKey]"
            }
          ],
          "numberOfWorkers": 1,
          "defaultDocuments": [
            "Default.htm",
            "Default.html",
            "Default.asp",
            "index.htm",
            "index.html",
            "iisstart.htm",
            "default.aspx",
            "index.php",
            "hostingstart.html"
          ],
          "netFrameworkVersion": "v4.6",
          "phpVersion": "",
          "pythonVersion": "",
          "nodeVersion": "",
          "linuxFxVersion": "",
          "requestTracingEnabled": false,
          "remoteDebuggingEnabled": false,
          "remoteDebuggingVersion": "VS2015",
          "httpLoggingEnabled": false,
          "logsDirectorySizeLimit": 35,
          "detailedErrorLoggingEnabled": false,
          "scmType": "None",
          "use32BitWorkerProcess": false,
          "webSocketsEnabled": false,
          "alwaysOn": true,
          "managedPipelineMode": "Integrated",
          "virtualApplications": [
            {
              "virtualPath": "/",
              "physicalPath": "site\\wwwroot",
              "preloadEnabled": false
            }
          ],
          "autoHealEnabled": false,
          "vnetName": ""
        },
        "microService": "WebSites",
        "clientAffinityEnabled": false,
        "clientCertEnabled": false,
        "hostNamesDisabled": false,
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
      },
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "Microsoft.ApplicationInsights.AzureWebSites",
          "type": "siteextensions",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {}

        }
      ]
    }
  ]
}
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "hostingPlanName": {
      "type": "string",
      "minLength": 1
    },
    "skuName": {
      "type": "string",
      "defaultValue": "F1",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "metadata": {
        "description": "Describes plan's instance count"
      }
    }
  },
  "variables": {
    "webSiteName": "brandotestarmfor"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "capacity": "[parameters('skuCapacity')]"
      },
      "properties": {
        "name": "[parameters('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "tags": {
        "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
        "displayName": "Website"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
      ],
      "properties": {
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]",
        "siteConfig": {
          "numberOfWorkers": 1,
          "defaultDocuments": [
            "Default.htm",
            "Default.html",
            "Default.asp",
            "index.htm",
            "index.html",
            "iisstart.htm",
            "default.aspx",
            "index.php",
            "hostingstart.html"
          ],
          "netFrameworkVersion": "v4.6",
          "phpVersion": "",
          "pythonVersion": "",
          "nodeVersion": "",
          "linuxFxVersion": "",
          "requestTracingEnabled": false,
          "remoteDebuggingEnabled": false,
          "remoteDebuggingVersion": "VS2015",
          "httpLoggingEnabled": false,
          "logsDirectorySizeLimit": 35,
          "detailedErrorLoggingEnabled": false,
          "scmType": "None",
          "use32BitWorkerProcess": false,
          "webSocketsEnabled": false,
          "alwaysOn": true,
          "managedPipelineMode": "Integrated",
          "virtualApplications": [
            {
              "virtualPath": "/",
              "physicalPath": "site\\wwwroot",
              "preloadEnabled": false
            }
          ],
          "autoHealEnabled": false,
          "vnetName": ""
        },
        "clientAffinityEnabled": false,
        "clientCertEnabled": false,
        "hostNamesDisabled": false
      },
      "resources": [
        {
          "name": "appsettings",
          "type": "config",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', variables('webSiteName'))]",
            "[resourceId('microsoft.insights/components', variables('webSiteName'))]",
            "Microsoft.ApplicationInsights.AzureWebSites"
          ],
          "properties": {
            "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('Microsoft.Insights/components', variables('webSiteName')), '2015-05-01').InstrumentationKey]",
            "UseAzureStorageEmulator": "false"
          }
        },
        {
          "apiVersion": "2015-08-01",
          "name": "Microsoft.ApplicationInsights.AzureWebSites",
          "type": "siteextensions",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {}
        }
      ]
    },
    {
      "apiVersion": "2014-04-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Insights/components",
      "location": "East US",
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites/', variables('webSiteName'))]"
      ],
      "tags": {
        "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('webSiteName'))]": "Resource",
        "displayName": "AppInsightsComponent"
      },
      "properties": {
        "applicationId": "[variables('webSiteName')]"
      }
    }
  ]
}
结果如下:


似乎没有办法让扩展等待应用程序设置更新,因此我将扩展的安装转移到发布环境中的另一个任务中。现在我有三项任务:

1.  ARM deploy common resources
2.  ARM deploy app dependencies and app service
3.  ARM deploy status monitor site extension
4.  Web Deploy code into app service
但是,为了做到这一点,您仍然必须在步骤3中以某种方式指定网站

下面是我使用步骤2的输出所做的,该输出具有webAppName,我必须再次指定站点,然后将扩展放入该站点的资源中。您必须注意此处指定的内容,以免中断以前的部署

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "webAppName": { "type": "string", "value": "<outputfrompreviousstep>" }
    },
    "variables": {
        "planName": "[concat(variables('webAppName'), '-ServicePlan')]"
    },
    "resources": [
        {
            "name": "[variables('webAppName')]",
            "type": "Microsoft.Web/sites",
            "apiVersion": "2016-08-01",
            "location": "[resourceGroup().location]",
            "tags": {},
            "dependsOn": [
            ],
            "properties": {
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('planName'))]"
            },
            "resources": [
                {
                    "apiVersion":"2015-08-01",
                    "name": "Microsoft.ApplicationInsights.AzureWebSites",
                    "type": "siteextensions",
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/Sites', variables('webAppName'))]"
                    ],
                    "properties": {}
                }
            ]
        }
    ],
    "outputs": {
        "webAppName": {
            "type": "string",
            "value": "[variables('webAppName')]"
        }
    }
}
{
“$schema”:”https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
“内容版本”:“1.0.0.0”,
“参数”:{
“webAppName”:{“类型”:“字符串”,“值”:“}
},
“变量”:{
“计划名称”:“[concat(变量('webAppName'),'-ServicePlan')”
},
“资源”:[
{
“名称”:“[变量('webAppName')]”,
“类型”:“Microsoft.Web/sites”,
“apiVersion”:“2016-08-01”,
“位置”:“[resourceGroup().location]”,
“标记”:{},
“dependsOn”:[
],
“财产”:{
“serverFarmId”:“[resourceId('Microsoft.Web/serverfarms',variables('planName'))”
},
“资源”:[
{
“apiVersion”:“2015-08-01”,
“名称”:“Microsoft.ApplicationInsights.AzureWebSites”,
“类型”:“站点扩展”,
“dependsOn”:[
[resourceId('Microsoft.Web/Sites',variables('webAppName'))]
],
“属性”:{}
}
]
}
],
“产出”:{
“webAppName”:{
“类型”:“字符串”,
“值”:“[变量('webAppName')]”
}
}
}

我故意将配置移出siteConfig,原因有二:1。配置需要部署其他资源,这使得站点在只有配置真正需要等待时等待。2.相同的配置与部署插槽共享,因此将其拔出似乎是有意义的。正如我的帖子所说,应用程序设置部署将在安装siteextensions时导致应用程序重新启动。在我看来,arm模板部署是第一步,您也不会将代码发布到web应用,因此它等待其他资源不会影响您的web应用。此外,如果您不想部署两次,则完全安装siteextensions的唯一方法是使用siteconfig而不使用appsetting。我建议你可以改变设计。我可以阅读并确认你的建议。。。有没有办法让扩展等待配置?将config放入siteConfig确实会无缘无故地造成巨大的延迟。Redis大约需要15分钟,如果不需要等待的话,该站点就可以部署。cosmos db是另一个需要很长时间才能完成的例子。如果必须的话,在vsts发布管道中创建2个步骤。首先在siteConfig之外部署资源和更新配置,然后安装扩展。我建议您可以使用站点扩展在appsetting中设置dependson,它将首先安装站点扩展,然后安装appsetting。这会很好的。我用白兰度的方法很成功。详细信息:如果您使用的是VSTS发布管道,则可以使用Azure应用程序服务管理任务来安装扩展,而不是处理ARM模板