この記事では、Azure Resource Manager テンプレート (ARM テンプレート) を使用して 、仮想マシン (VM) 拡張機能 を Azure Arc 対応サーバーにデプロイする方法について説明します。
ARM テンプレートを使用して Arc 対応サーバーに拡張機能をデプロイするには、拡張機能をテンプレートに追加し、テンプレートデプロイで実行します。 拡張機能は、Azure PowerShell を使用して Linux または Windows に接続されたマシンにデプロイできます。
この記事では、テンプレート ファイルと、一部の拡張機能用の個別のパラメーター ファイルを使用して、複数の異なる VM 拡張機能を Arc 対応サーバーにデプロイする方法について説明します。 デプロイする前に、サンプルのサンプル値を独自の値に置き換えます。
デプロイ コマンド
これらの PowerShell サンプル コマンドは、ARM テンプレート内の情報に基づいて、リソース グループ内のすべての接続されたマシンに拡張機能をインストールします。 このコマンドでは、 TemplateFile
パラメーターを使用してテンプレートを指定します。 パラメーター ファイルが必要な場合は、パラメーターとパラメーター値を含むファイルを指定するために、 TemplateParameterFile
パラメーターが含まれます。 プレースホルダーをデプロイに適した値に置き換えます。
ARM テンプレートとパラメーター ファイルをデプロイするには、次のコマンドを使用して、例の値を独自の値に置き換えます。
New-AzResourceGroupDeployment -ResourceGroupName "<resource-group-name>" -TemplateFile "<template-filename.json>" -TemplateParameterFile "<parameter-filename.json>"
例えば次が挙げられます。
New-AzResourceGroupDeployment -ResourceGroupName "ContosoEngineering" -TemplateFile "D:\Azure\Templates\AzureMonitorAgent.json" -TemplateParameterFile "D:\Azure\Templates\AzureMonitorAgentParms.json"
パラメーター ファイルなしで ARM テンプレートをデプロイするには、次のコマンドを使用して、例の値を独自の値に置き換えます。
New-AzResourceGroupDeployment -ResourceGroupName "<resource-group-name>" -TemplateFile "<template-filename.json>>"
例えば次が挙げられます。
New-AzResourceGroupDeployment -ResourceGroupName "<ContosoEngineering>" -TemplateFile "D:\Azure\Templates\DependencyAgent.json"
Azure Monitor エージェント VM 拡張機能をデプロイする
Azure Monitor エージェントをデプロイするには、次のいずれかのサンプル テンプレートを使用して、Linux または Windows にエージェントをインストールします。
Linux 用 Azure Monitor エージェント テンプレート ファイル
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
},
"___location": {
"type": "string"
},
"workspaceId": {
"type": "string"
},
"workspaceKey": {
"type": "string"
}
},
"resources": [
{
"name": "[concat(parameters('vmName'),'/AzureMonitorLinuxAgent')]",
"type": "Microsoft.Compute/machines/extensions",
"___location": "[parameters('___location')]",
"apiVersion": "2021-11-01",
"properties": {
"publisher": "Microsoft.Azure.Monitor",
"type": "AzureMonitorLinuxAgent",
"enableAutomaticUpgrade": true,
"settings": {
"workspaceId": "[parameters('workspaceId')]"
},
"protectedSettings": {
"workspaceKey": "[parameters('workspaceKey')]"
}
}
}
]
}
Windows 用 Azure Monitor エージェント テンプレート ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
},
"___location": {
"type": "string"
},
"workspaceId": {
"type": "string"
},
"workspaceKey": {
"type": "string"
}
},
"resources": [
{
"name": "[concat(parameters('vmName'),'/AzureMonitorWindowsAgent')]",
"type": "Microsoft.Compute/machines/extensions",
"___location": "[parameters('___location')]",
"apiVersion": "2021-11-01",
"properties": {
"publisher": "Microsoft.Azure.Monitor",
"type": "AzureMonitorWindowsAgent",
"autoUpgradeMinorVersion": true,
"enableAutomaticUpgrade": true,
"settings": {
"workspaceId": "[parameters('workspaceId')]"
},
"protectedSettings": {
"workspaceKey": "[parameters('workspaceKey')]"
}
}
}
]
}
Azure Monitor エージェント パラメーター ファイル
このパラメーター ファイルは、Linux と Windows の両方で使用できます。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"value": "<vmName>"
},
"___location": {
"value": "<region>"
},
"workspaceId": {
"value": "<MyWorkspaceID>"
},
"workspaceKey": {
"value": "<MyWorkspaceKey>"
}
}
}
テンプレートとパラメーター ファイルを保存し、デプロイに適した値を使用してパラメーター ファイルを編集します。 次に、この記事で前述した PowerShell デプロイ コマンド を実行して、接続されているマシンに Azure Monitor エージェント拡張機能をインストールします。
カスタム スクリプト拡張機能をデプロイする
カスタム スクリプト拡張機能を使用するには、Linux および Windows 用の次のサンプル テンプレートのいずれかをデプロイします。 カスタム スクリプト拡張機能の詳細については、「 Linux 用のカスタム スクリプト拡張機能 」または 「Windows 用カスタム スクリプト拡張機能」を参照してください。 ハイブリッド マシンでこの拡張機能を使用する場合は、いくつかの異なる特性を理解する必要があります。
- Azure VM カスタム スクリプト拡張機能でサポートされているオペレーティング システムの一覧は、Azure Arc 対応サーバーには適用されません。 Azure Arc 対応サーバーでサポートされているオペレーティング システムの一覧でご確認ください。
- クラシック デプロイ モデルを使用して作成された Azure 仮想マシン スケール セットまたは VM に関する構成の詳細は適用されません。
- ご使用のマシンで、スクリプトを外部からダウンロードする必要があり、通信できるのがプロキシ サーバー経由のみである場合には、Connected Machine エージェントを構成してプロキシ サーバーの環境変数を設定する必要があります。
カスタム スクリプト拡張機能の構成では、スクリプトの場所や、実行するコマンドなどを指定します。 この構成は、次のテンプレート内で指定されます。
Linux 用のカスタム スクリプト拡張機能テンプレート ファイル
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
},
"___location": {
"type": "string"
},
"fileUris": {
"type": "array"
},
"commandToExecute": {
"type": "securestring"
}
},
"resources": [
{
"name": "[concat(parameters('vmName'),'/CustomScript')]",
"type": "Microsoft.HybridCompute/machines/extensions",
"___location": "[parameters('___location')]",
"apiVersion": "2022-03-10",
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"autoUpgradeMinorVersion": true,
"settings": {},
"protectedSettings": {
"commandToExecute": "[parameters('commandToExecute')]",
"fileUris": "[parameters('fileUris')]"
}
}
}
]
}
Windows 用のカスタム スクリプト テンプレート ファイル
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
},
"___location": {
"type": "string"
},
"fileUris": {
"type": "string"
},
"arguments": {
"type": "securestring",
"defaultValue": " "
}
},
"variables": {
"UriFileNamePieces": "[split(parameters('fileUris'), '/')]",
"firstFileNameString": "[variables('UriFileNamePieces')[sub(length(variables('UriFileNamePieces')), 1)]]",
"firstFileNameBreakString": "[split(variables('firstFileNameString'), '?')]",
"firstFileName": "[variables('firstFileNameBreakString')[0]]"
},
"resources": [
{
"name": "[concat(parameters('vmName'),'/CustomScriptExtension')]",
"type": "Microsoft.HybridCompute/machines/extensions",
"___location": "[parameters('___location')]",
"apiVersion": "2022-03-10",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": "[split(parameters('fileUris'), ' ')]"
},
"protectedSettings": {
"commandToExecute": "[concat ('powershell -ExecutionPolicy Unrestricted -File ', variables('firstFileName'), ' ', parameters('arguments'))]"
}
}
}
]
}
カスタム スクリプト パラメーター ファイル
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{}
],
"steps": [
{
"name": "customScriptExt",
"label": "Add Custom Script Extension",
"elements": [
{
"name": "fileUris",
"type": "Microsoft.Common.FileUpload",
"label": "Script files",
"toolTip": "The script files that will be downloaded to the virtual machine.",
"constraints": {
"required": false
},
"options": {
"multiple": true,
"uploadMode": "url"
},
"visible": true
},
{
"name": "commandToExecute",
"type": "Microsoft.Common.TextBox",
"label": "Command",
"defaultValue": "sh script.sh",
"toolTip": "The command to execute, for example: sh script.sh",
"constraints": {
"required": true
},
"visible": true
}
]
}
],
"outputs": {
"vmName": "[vmName()]",
"___location": "[___location()]",
"fileUris": "[steps('customScriptExt').fileUris]",
"commandToExecute": "[steps('customScriptExt').commandToExecute]"
}
}
}
テンプレートとパラメーター ファイルを保存し、デプロイに適した値を使用してパラメーター ファイルを編集します。 次に、この記事で前述した PowerShell デプロイ コマンド を実行して、接続されているマシンにカスタム スクリプト拡張機能をインストールします。
Dependency Agent 拡張機能をデプロイする
Azure Monitor Dependency Agent 拡張機能を使用するには、Linux および Windows 用に次のいずれかのサンプルを実行します。 Dependency Agent の詳細については、「 Azure Monitor エージェントの概要」を参照してください。
Linux 用の Dependency Agent テンプレート ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string",
"metadata": {
"description": "The name of existing Linux machine."
}
}
},
"resources": [
{
"type": "Microsoft.HybridCompute/machines/extensions",
"name": "[concat(parameters('vmName'),'/DAExtension')]",
"apiVersion": "2022-03-10",
"___location": "[resourceGroup().___location]",
"dependsOn": [
],
"properties": {
"publisher": "Microsoft.Azure.Monitoring.DependencyAgent",
"type": "DependencyAgentLinux",
"enableAutomaticUpgrade": true
}
}
],
"outputs": {
}
}
Windows 用の Dependency Agent テンプレート ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string",
"metadata": {
"description": "The name of existing Windows machine."
}
}
},
"resources": [
{
"type": "Microsoft.HybridCompute/machines/extensions",
"name": "[concat(parameters('vmName'),'/DAExtension')]",
"apiVersion": "2022-03-10",
"___location": "[resourceGroup().___location]",
"dependsOn": [
],
"properties": {
"publisher": "Microsoft.Azure.Monitoring.DependencyAgent",
"type": "DependencyAgentWindows",
"enableAutomaticUpgrade": true
}
}
],
"outputs": {
}
}
テンプレートを保存し、この記事で前述した PowerShell デプロイ コマンド を実行して、接続されているマシンに Dependency Agent 拡張機能をインストールします。
Azure Key Vault 拡張機能をデプロイする
次の JSON は、Azure Key Vault 拡張機能のスキーマを示しています。 この拡張機能では、すべての設定が公開情報と見なされるため、保護された設定は必要ありません。 この拡張機能には、監視対象の証明書、ポーリング頻度、および宛先の証明書ストアのリストが必要です。
Linux 用 Azure Key Vault テンプレート ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
},
"___location": {
"type": "string"
},
"autoUpgradeMinorVersion":{
"type": "bool"
},
"pollingIntervalInS":{
"type": "int"
},
"certificateStoreName":{
"type": "string"
},
"certificateStoreLocation":{
"type": "string"
},
"observedCertificates":{
"type": "string"
},
"msiEndpoint":{
"type": "string"
},
"msiClientId":{
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.HybridCompute/machines/extensions",
"name": "[concat(parameters('vmName'),'/KVVMExtensionForLinux')]",
"apiVersion": "2022-03-10",
"___location": "[parameters('___location')]",
"properties": {
"publisher": "Microsoft.Azure.KeyVault",
"type": "KeyVaultForLinux",
"enableAutomaticUpgrade": true,
"settings": {
"secretsManagementSettings": {
"pollingIntervalInS": <polling interval in seconds, e.g. "3600">,
"certificateStoreName": <ignored on linux>,
"certificateStoreLocation": <disk path where certificate is stored, default: "/var/lib/waagent/Microsoft.Azure.KeyVault">,
"observedCertificates": <list of KeyVault URIs representing monitored certificates, e.g.: "https://myvault.vault.azure.net/secrets/mycertificate"
},
"authenticationSettings": {
"msiEndpoint": "http://localhost:40342/metadata/identity"
}
}
}
}
]
}
Windows 用 Azure Key Vault テンプレート ファイル
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
},
"___location": {
"type": "string"
},
"autoUpgradeMinorVersion":{
"type": "bool"
},
"pollingIntervalInS":{
"type": "int"
},
"certificateStoreName":{
"type": "string"
},
"linkOnRenewal":{
"type": "bool"
},
"certificateStoreLocation":{
"type": "string"
},
"requireInitialSync":{
"type": "bool"
},
"observedCertificates":{
"type": "string"
},
"msiEndpoint":{
"type": "string"
},
"msiClientId":{
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.HybridCompute/machines/extensions",
"name": "[concat(parameters('vmName'),'/KVVMExtensionForWindows')]",
"apiVersion": "2022-03-10",
"___location": "[parameters('___location')]",
"properties": {
"publisher": "Microsoft.Azure.KeyVault",
"type": "KeyVaultForWindows",
"enableAutomaticUpgrade": true,
"settings": {
"secretsManagementSettings": {
"pollingIntervalInS": "3600",
"certificateStoreName": <certificate store name, e.g.: "MY">,
"linkOnRenewal": <Only Windows. This feature ensures s-channel binding when certificate renews, without necessitating a re-deployment. e.g.: false>,
"certificateStoreLocation": <certificate store ___location, currently it works locally only e.g.: "LocalMachine">,
"requireInitialSync": <initial synchronization of certificates e.g.: true>,
"observedCertificates": <list of KeyVault URIs representing monitored certificates, e.g.: "https://myvault.vault.azure.net"
},
"authenticationSettings": {
"msiEndpoint": "http://localhost:40342/metadata/identity"
}
}
}
}
]
}
注
実際の証明書の URL は、https://myVaultName.vault.azure.net/secrets/myCertName
の形式である必要があります。 その理由は、/secrets
パスは秘密キーを含む完全な証明書を返すのに対し、/certificates
パスはそれを返さないためです。 証明書の詳細については、「 Azure Key Vault のキー、シークレット、および証明書の概要」を参照してください。
テンプレートを保存し、環境に合わせて必要に応じて編集します。 次に、この記事で前述した PowerShell デプロイ コマンド を実行して、接続されているマシンに Azure Key Vault 拡張機能をインストールします。
ヒント
Azure Key Vault 拡張機能では、Key Vault に対する認証を行うために、システム割り当て ID を割り当てる必要があります。 詳細については、「 Azure Arc 対応サーバーを使用した Azure リソースに対する認証」を参照してください。
関連コンテンツ
- Azure Arc 対応サーバーでサポートされている VM 拡張機能について詳しくは、こちらをご覧ください。
- Azure PowerShell、Azure portal、または Azure CLI を使用して VM 拡張機能をデプロイ、管理、削除する方法について説明します。
- VM 拡張機能のトラブルシューティングに関するガイドのトラブルシューティング情報について説明します。