可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am trying to add app settings to my Azure Website via the JSON template files as part of the Azure Resource Manager.
In an Azure Resource template json file, there are examples for creating connectionStrings directly from the JSON template file with a sub-dependency of type 'config' with properties for 'connectionStrings' as in the final example here http://haishibai.blogspot.co.uk/2014/09/tutorial-building-azure-template.html I have also checked in the website schema definition for websites here http://schema.management.azure.com/schemas/2014-06-01/Microsoft.Web.json#/definitions/sites and cannot see that it is possible.
Is it possible to define a websites app settings for resource manager deployments from the JSON template file? And if so any links or details would be greatly appreciated.
(I have already tried properties of appSettings inside the config resource and inside the website resource)
回答1:
I have a sample that shows how to do this here. It looks like this:
{
"apiVersion": "2014-11-01",
"name": "appsettings",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
],
"properties": {
"AppSettingKey1": "Some value",
"AppSettingKey2": "My second setting",
"AppSettingKey3": "My third setting"
}
}
Please make sure you use the newest 2014-11-01 API, as the way it deals with app settings is a bit different from the older API.
回答2:
With thanks to Simon Pedersen - properties/siteConfig/appSettings
works as of November 2015.
{
"apiVersion": "2014-06-01",
"name": "[concat(parameters('siteName'),copyIndex())]",
"type": "Microsoft.Web/sites",
"location": "[parameters('siteLocations')[copyIndex()]]",
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
"displayName": "Website"
},
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', concat(parameters('hostingPlanName'),copyIndex()))]",
"[concat('Microsoft.Storage/storageAccounts/', parameters('newStorageAccountName'))]"
],
"properties": {
"name": "[concat(parameters('siteName'),copyIndex())]",
"serverFarm": "[concat(parameters('hostingPlanName'),copyIndex())]",
"siteConfig": {
"appSettings": [
{
"name": "AzureStorageAccount",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('newStorageAccountName'),';AccountKey=',listKeys(variables('storageid'),'2015-05-01-preview').key1)]"
}
]
}
},
"copy": {
"name": "siteCopy",
"count": "[parameters('numberOfSites')]"
}
}
回答3:
Here is the solution for the latest release 2014-06-01 version of API.
"resources": [
{
"apiVersion": "2014-06-01",
"name": "[parameters('webSiteName')]",
"type": "Microsoft.Web/sites",
"location": "[parameters('webSiteLocation')]",
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('webSiteHostingPlanName'))]": "Resource",
"displayName": "WebSite"
},
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', parameters('webSiteHostingPlanName'))]"
],
"properties": {
"name": "[parameters('webSiteName')]",
"serverFarm": "[parameters('webSiteHostingPlanName')]"
},
"resources": [
{
"apiVersion": "2014-04-01",
"name": "MSDeploy",
"type": "extensions",
"dependsOn": [
"[concat('Microsoft.Web/Sites/', parameters('webSiteName'))]"
],
"properties": {
"packageUri": "[concat(parameters('dropLocation'), '/', parameters('webSitePackage'), parameters('dropLocationSasToken'))]",
"dbType": "None",
"connectionString": "",
"setParameters": {
"IIS Web Application Name": "[parameters('webSiteName')]"
}
}
},
{
"apiVersion": "2014-04-01",
"name": "web",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('webSiteName'))]"
],
"properties": {
"connectionStrings": [
{
"ConnectionString": "AzureWebJobsStorage",
"Name": "CustomConnectionString1"
},
{
"ConnectionString": "AzureWebJobsStorage",
"Name": "CustomConnectionString2"
}
],
"appSettings": [
{
"Name": "Key1",
"Value": "Value1"
},
{
"Name": "Key2",
"Value": "Value2"
}
]
}
}
]
},
回答4:
Adding as a sub/child resource fails to work using the later API's, however adding a "siteConfig" property with an "appSettings" element, as stated above, seems to work. I am using the API Version 2016-03-01
{
"type": "Microsoft.Web/sites",
"name": "[variables('webappName')]",
"apiVersion": "2016-03-01",
"location": "[parameters('location')]",
"tags": "[parameters('tags')]",
"kind": "app",
"properties": {
"name": "[variables('webappName')]",
"serverFarmId": "[variables('targetResourceId')]",
"hostingEnvironment": "[parameters('hostingEnvironment')]",
"netFrameworkVersion": "[parameters('netFrameworkVersion')]",
"use32BitWorkerProcess": false,
"webSocketsEnabled": true,
"alwaysOn": true,
"managedPipelineMode": "integrated",
"clientAffinityEnabled": true,
"hostNameSslStates": [
{
"name": "[variables('hostName')]",
"sslState": "SniEnabled",
"thumbprint": "[parameters('certThumb')]",
"ipBasedSslState": "NotConfigured",
"hostType": "Standard"
}
],
"siteConfig": {
"appSettings": "[variables('appSettings')]"
}
},
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', variables('hostingPlanName'))]"
],
"resources": []
}
And my variable looks like this.....
"appSettings": [
{
"name": "WEBSITE_NODE_DEFAULT_VERSION",
"value": "8.9.3"
},
{
"name": "WEBSITE_PRIVATE_EXTENSIONS",
"value": "0"
},
{
"name": "MobileAppsManagement_EXTENSION_VERSION",
"value": "latest"
},
{
"name": "WEBSITE_LOAD_CERTIFICATES",
"value": "*"
}
]