6

我正在尝试通过 JSON 模板文件将应用程序设置添加到我的 Azure 网站,作为 Azure 资源管理器的一部分。

在 Azure 资源模板 json 文件中,有一些示例可以直接从 JSON 模板文件创建 connectionStrings,其子依赖项类型为“config”,属性为“connectionStrings”,如http://haishibai.blogspot 中的最后一个示例。 co.uk/2014/09/tutorial-building-azure-template.html我还在这里检查了网站的网站架构定义http://schema.management.azure.com/schemas/2014-06-01/Microsoft .Web.json#/definitions/sites并且看不到这是可能的。

是否可以从 JSON 模板文件为资源管理器部署定义网站应用程序设置?如果是这样,任何链接或细节将不胜感激。

(我已经在配置资源和网站资源中尝试过 appSettings 的属性)

4

4 回答 4

18

我有一个示例,显示如何在此处执行此操作。它看起来像这样:

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

请确保您使用最新的 2014-11-01 API,因为它处理应用程序设置的方式与旧 API 略有不同。

于 2014-12-23T17:57:28.323 回答
10

感谢Simon Pedersen -properties/siteConfig/appSettings截至 2015 年 11 月的作品。

{
    "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')]"
    }
}
于 2015-10-27T01:19:09.057 回答
3

这是最新发布的2014-06-01 版本 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"
                        }
                    ]
                }
            }
        ]
    },
于 2015-02-04T22:10:28.903 回答
3

添加为子/子资源无法使用后来的 API 工作,但是如上所述,添加带有“appSettings”元素的“siteConfig”属性似乎有效。我正在使用 API 版本 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": []
    }

我的变量看起来像这样......

"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": "*"
            }
        ]
于 2018-08-09T06:16:39.307 回答