12
votes

I just started getting this failure, not sure why; it was working fine yesterday. I only changed the appsettings and connectionstrings to be part or resources instead of the webapp to move the dependsOn down the chain. Previously, the site was dependsOn the dependencies for app settings and connection strings. Here is the ARM template for the website resource.

{
        "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": {}
            }
        ]
    }

And the error I'm getting...

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'."
    }
}

Even with the error, it actually did install the extension correctly. During another test, it installed the extension, but when I opened it, the App Insights Profiler web job was not installed. Either way, not sure why there is a conflict. When I open the log in Kudu, there is pretty much nothing inside.

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.

That's the entirety of the log.

On a previous test...

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.

Same start of the file, but there are more entries. There is definitely a web config and the app is working so not sure what that's about.

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'.

The app is definitely instrumented and uses version 2.4 which is newer than 2.3 which was installed.

2

2 Answers

16
votes

According to your description, I think the reason why the siteextensions installed has been canceled is changed the appsetting the web app will restarted.So it will cancel the siteextensions installed thread.

After the deployment changed the web app appsetting, it will restart the web app. But your deployment still running the thread which installing the siteextensions. So you face the thread canceled error.

I suggest you could set the appsettings during the web app resource's siteConfig feature. When you deploy the template, it will not cause the web app restart while installing the siteextensions.

Some part of the template you could refer to below codes:

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

The whole test template:

{
  "$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": {}

        }
      ]
    }
  ]
}

The result:

enter image description here


Update:

I suggest you could firstly install the web site extensions, then change the appsetting.

In the web app config resources, you could set its depend on the web site extensions.

So the template will firstly install the extensions, then change the appsetting to make the web app restart. So you could install the extensions complete.

More details, you could refer to below template:

You could set the dependsOn with "Microsoft.ApplicationInsights.AzureWebSites".

 "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"
          }
        },

The total template:

{
  "$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')]"
      }
    }
  ]
}

The result like this:

enter image description here

8
votes

There seems to be no way to make the extension wait on app setting update so I moved the installation of the extension into a different task in the release environment. Now I have three tasks:

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

However, in order to do this, you have to still specify the website somehow in step 3.

Here is what I did using the output from step 2 which has the webAppName, I had to specify the site again and then place the extension into the resources for that site. You must be careful about what you specify here as to not disrupt the previous deployment.

{
    "$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')]"
        }
    }
}