この記事では、Azure コンピューティング ギャラリーで発行済み VM アプリケーションを表示、更新、削除する方法について説明します。 次に、デプロイされた VM アプリケーション リソースを、Azure仮想マシン (VM) またはVirtual Machine Scale Setsで表示、監視、更新、削除する方法について説明します。
Azure コンピューティング ギャラリーに発行されたマネージド VM アプリケーション
このセクションでは、Azure コンピューティング ギャラリーで発行済み VM アプリケーションを表示、更新、および削除する方法について説明します。
発行された VM アプリケーションを表示する
Azure ポータルで発行済み VM アプリケーションのプロパティを表示するには:
-
Azure ポータルにサインインします。
-
Azure Compute Gallery を検索します。
- VM アプリケーションを含むギャラリーを選択します。
- 表示する VM アプリケーション名 をクリックします。
- [ 概要]/[プロパティ] ブレードには、VM アプリケーションに関する情報が表示されます。
- [ 概要]/[バージョン] ブレードには、公開されているすべてのバージョンとその基本プロパティ (ターゲット リージョン、プロビジョニング状態、レプリケーション状態など) が表示されます。
- 特定の バージョン を選択すると、そのすべての詳細が表示されます。
&&&Azure portal の VM アプリケーションバージョンのプロパティを示すスクリーンショット&&
REST API を使用して、発行された VM アプリケーションまたは特定のバージョンのプロパティを表示します。
VM アプリケーションの詳細を取得します。
GET
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}?api-version=2024-03-03
応答の例:
{
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}",
"name": "{galleryApplicationName}",
"type": "Microsoft.Compute/galleries/applications",
"location": "eastus",
"properties": {
"description": "Sample VM Application",
"provisioningState": "Succeeded",
"supportedOSTypes": ["Windows", "Linux"],
"endOfLifeDate": null,
"privacyStatementUri": "https://contoso.com/privacy",
"releaseNoteUri": "https://contoso.com/release-notes"
}
}
VM アプリケーションのバージョンの詳細を取得します。
GET
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}/versions/{galleryApplicationVersionName}?api-version=2024-03-03
応答の例:
{
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}/versions/{galleryApplicationVersionName}",
"name": "{galleryApplicationVersionName}",
"type": "Microsoft.Compute/galleries/applications/versions",
"location": "eastus",
"properties": {
"provisioningState": "Succeeded",
"publishingProfile": {
"source": {
"mediaLink": "https://storageaccount.blob.core.windows.net/vmapps/app.zip"
},
"replicaCount": 1,
"targetRegions": [
{
"name": "eastus",
"regionalReplicaCount": 1
}
]
},
"storageAccountType": "Standard_LRS"
}
}
応答には、名前、場所、プロビジョニング状態、説明、アプリケーションまたはバージョンに関するその他のメタデータなどのプロパティが含まれます。
変数を設定します。
rgName="myResourceGroup"
galleryName="myGallery"
appName="myVmApp"
versionName="1.0.0"
ギャラリー内のすべての VM アプリケーションを一覧表示します。
az sig gallery-application list \
--resource-group $rgName \
--gallery-name $galleryName \
-o table
VM アプリケーションのプロパティを表示します。
az sig gallery-application show \
--resource-group $rgName \
--gallery-name $galleryName \
--application-name $appName
VM アプリケーションのすべてのバージョンを一覧表示します。
az sig gallery-application version list \
--resource-group $rgName \
--gallery-name $galleryName \
--application-name $appName \
--query "[].{version:name, provisioningState:properties.provisioningState}" -o table
特定の VM アプリケーション バージョンのプロパティを表示します。
az sig gallery-application version show \
--resource-group $rgName \
--gallery-name $galleryName \
--application-name $appName \
--version-name $versionName
Azure PowerShellを使用して、Azure コンピューティング ギャラリーで VM アプリケーションとバージョンの詳細を表示します。
変数を設定します。
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$appName = "myVmApp"
$versionName = "1.0.0"
ギャラリー内のすべての VM アプリケーションを一覧表示します。
Get-AzGalleryApplication `
-ResourceGroupName $rgName `
-GalleryName $galleryName |
Select-Object Name, Location, ProvisioningState
VM アプリケーションのプロパティを表示します。
Get-AzGalleryApplication `
-ResourceGroupName $rgName `
-GalleryName $galleryName `
-Name $appName |
ConvertTo-Json -Depth 5
VM アプリケーションのすべてのバージョンを一覧表示します。
Get-AzGalleryApplicationVersion `
-ResourceGroupName $rgName `
-GalleryName $galleryName `
-GalleryApplicationName $appName |
Select-Object Name, @{n="ProvisioningState";e={$_.ProvisioningState}}
特定の VM アプリケーション バージョンのプロパティを表示します。
Get-AzGalleryApplicationVersion `
-ResourceGroupName $rgName `
-GalleryName $galleryName `
-GalleryApplicationName $appName `
-Name $versionName |
ConvertTo-Json -Depth 6
Azure Resource Graphを使用して発行された VM アプリケーションを表示する
Azure リソース グラフ クエリを使用すると、すべてのコンピューティング ギャラリーで発行されたすべての VM アプリケーションとそのプロパティを表示できます。 アプリケーション インベントリとそのプロパティを大規模に表示するプログラムによる方法が提供されます。 ダッシュボードやカスタム レポートと統合する場合は、この方法を使用します。
すべてのコンピューティング ギャラリーの一覧を表示する
resources
| where type == "microsoft.compute/galleries"
| where subscriptionId == "85236c53-92ad-4e66-97a4-8253a5246b99"
| extend provisioningState = properties["provisioningState"]
| extend permissions = properties["sharingProfile"]["permissions"]
| extend communityGalleryInfo = properties["sharingProfile"]["communityGalleryInfo"]
| project subscriptionId, resourceGroup, location, name, provisioningState, permissions, communityGalleryInfo
すべてのギャラリーで公開されているすべての VM アプリケーションの一覧を表示する
resources
| where subscriptionId == "85236c53-92ad-4e66-97a4-8253a5246b99"
| where type == "microsoft.compute/galleries/applications"
| extend OSType = properties["supportedOSType"]
| extend description = properties["description"]
| extend endOfLifeDate = properties["endOfLifeDate"]
| parse id with "/subscriptions/" SubId "/resourceGroups/" rgName "/providers/Microsoft.Compute/galleries/" gallaryName "/applications/" appName
| project subscriptionId, resourceGroup, location, gallaryName, name, OSType, description
すべてのアプリケーションとギャラリーで公開されているすべての VM アプリケーション バージョンの一覧を表示する
resources
| where type == "microsoft.compute/galleries/applications/versions"
| project subscriptionId, resourceGroup, id, location, properties
| parse id with "/subscriptions/" SubId "/resourceGroups/" rgName "/providers/Microsoft.Compute/galleries/" gallaryName "/applications/" appName "/versions/" versionNumber
| extend provisioningState = properties["provisioningState"]
| extend publishingProfile = properties["publishingProfile"]
| extend storageAccountType = publishingProfile["storageAccountType"]
| extend scriptBehaviorAfterReboot = publishingProfile["settings"]["scriptBehaviorAfterReboot"]
| extend packageFileName = publishingProfile["settings"]["packageFileName"]
| extend configFileName = publishingProfile["settings"]["configFileName"]
| extend mediaLink = publishingProfile["source"]["mediaLink"]
| extend defaultConfigurationLink = publishingProfile["source"]["defaultConfigurationLink"]
| extend excludeFromLatest = publishingProfile["excludeFromLatest"]
| extend targetRegions = publishingProfile["targetRegions"]
| extend replicaCount = publishingProfile["replicaCount"]
| extend publishedDate = publishingProfile["publishedDate"]
| extend installScript = publishingProfile["manageActions"]["install"]
| extend removeScript = publishingProfile["manageActions"]["remove"]
| extend safetyProfile = properties["safetyProfile"]
| extend allowDeletionOfReplicatedLocations = safetyProfile["allowDeletionOfReplicatedLocations"]
| project-away safetyProfile, publishingProfile, SubId, rgName, id, properties
発行された VM アプリケーションを更新する
注
発行された VM アプリケーションまたは VM アプリケーションのバージョンのすべてのプロパティを更新できるわけではありません。 更新可能なプロパティの完全な一覧については、 VM アプリケーション リソースと VM アプリケーションバージョンのリソース スキーマを参照してください。
VM アプリケーション リソースの更新:
PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}?api-version=2024-03-03
Body
{
"properties": {
"description": "Updated description",
"endOfLifeDate": "2026-12-31T00:00:00Z",
"eula": "Updated EULA text",
"privacyStatementUri": "https://contoso.com/privacy",
"releaseNoteUri": "https://contoso.com/release-notes"
}
}
VM アプリケーション のバージョン リソースを更新します。
PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}/versions/{galleryApplicationVersionName}?api-version=2024-03-03
Body
{
"properties": {
"publishingProfile": {
"targetRegions": [
{
"name": "eastus",
"regionalReplicaCount": 2,
"storageAccountType": "Standard_LRS"
},
{
"name": "westus",
"regionalReplicaCount": 1,
"storageAccountType": "Standard_LRS"
}
],
"excludeFromLatest": false
}
}
}
VM アプリケーション リソースの更新:
az sig gallery-application update \
--resource-group $rgName \
--gallery-name $galleryName \
--application-name $appName \
--description "Updated description for the VM Application"
VM アプリケーション のバージョン リソースを更新します。
az sig gallery-application version update \
--resource-group $rgName \
--gallery-name $galleryName \
--application-name $appName \
--version-name $versionName \
--target-regions "eastus=2" "westus=1"
変数を設定します。
$rgName = "myResourceGroup"
$galleryName = "myGallery"
$appName = "myVmApp"
$versionName = "1.0.0"
VM アプリケーション リソースの更新:
$app = Get-AzGalleryApplication `
-ResourceGroupName $rgName `
-GalleryName $galleryName `
-Name $appName
Update-AzGalleryApplication `
-ResourceGroupName $rgName `
-GalleryName $galleryName `
-Name $appName `
-Description "Updated description for the VM Application"
VM アプリケーション のバージョン リソースを更新します。
$targetRegions = @(
@{
Name = "eastus"
RegionalReplicaCount = 2
StorageAccountType = "Standard_LRS"
},
@{
Name = "westus"
RegionalReplicaCount = 1
StorageAccountType = "Standard_LRS"
}
)
Update-AzGalleryApplicationVersion `
-ResourceGroupName $rgName `
-GalleryName $galleryName `
-GalleryApplicationName $appName `
-Name $versionName `
-PublishingProfileTargetRegion $targetRegions `
-PublishingProfileExcludeFromLatest:$false
発行済み VM アプリケーションAzureコンピューティング ギャラリーから削除する
VM アプリケーション リソースを削除するには、まず、そのすべてのバージョンを削除する必要があります。 アプリケーション のバージョンを削除すると、Azure コンピューティング ギャラリーとそのすべてのレプリカからアプリケーション バージョン リソースが削除されます。 アプリケーション バージョンの作成に使用されるストレージ アカウント内のアプリケーション BLOB は影響を受けません。
Warnung
アプリケーションのバージョンを削除すると、そのバージョンを使用している VM に対する後続の PUT 操作が失敗します。 このエラーを回避するには、バージョン番号をハード コーディングする代わりに、のバージョン番号として キーワードを使用します。
任意の VM またはVirtual Machine Scale Setsにデプロイされている VM アプリケーションを削除すると、これらのリソースに対する後続の PUT 操作が失敗します (更新、スケール、再イメージ化など)。 削除する前に、すべての VM/Virtual Machine Scale Sets インスタンスが applicationProfile からアプリケーションを削除してアプリケーションの使用を停止していることを確認します。
誤って削除されないようにするには、バージョンの発行時に safetyProfile/allowDeletionOfReplicatedLocations を false に設定し、VM アプリケーション リソースにAzure Resource Manager ロック (CanNotDelete または ReadOnly) を適用します。
-
Azure ポータルにサインインします。
- コンピューティング ギャラリー Azure検索し、ターゲット ギャラリーを開きます。
- 削除する VM アプリケーションを選択します。
- 削除する 1 つ以上のバージョンを選択します。
- VM アプリケーションを削除するには、まずすべてのバージョンを削除します。 次に、(ブレードの上部にある) [削除] をクリックします。
- 通知の完了を監視します。 削除がブロックされている場合は、ロックを削除し、VM またはVirtual Machine Scale Setsがアプリケーションを参照しないようにします。
VM アプリケーションのバージョンを削除します。
DELETE
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}/versions/{galleryApplicationVersionName}?api-version=2024-03-03
すべてのバージョンが削除された後、VM アプリケーションを削除します。
DELETE
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}?api-version=2024-03-03
VM アプリケーションのバージョンを削除します。
az sig gallery-application version delete --resource-group $rg-name --gallery-name $gallery-name --application-name $app-name --version-name $version-name
すべてのバージョンが削除された後、VM アプリケーションを削除します。
az sig gallery-application delete --resource-group $rg-name --gallery-name $gallery-name --application-name $app-name
VM アプリケーションのバージョンを削除します。
Remove-AzGalleryApplicationVersion -ResourceGroupName $rgNmae -GalleryName $galleryName -GalleryApplicationName $galleryApplicationName -Name $name
すべてのバージョンが削除された後、VM アプリケーションを削除します。
Remove-AzGalleryApplication -ResourceGroupName $rgNmae -GalleryName $galleryName -Name $name
デプロイされた VM アプリケーションAzure VM とVirtual Machine Scale Setsで管理する
このセクションでは、デプロイされたアプリケーションの詳細を表示し、インフラストラクチャ全体でデプロイされたアプリケーションを監視する方法について説明します。 また、Azure VM とVirtual Machine Scale Setsデプロイされた VM アプリケーションを更新および削除する方法についても説明します。
デプロイされた VM アプリケーションとその状態を表示する
Azureでは、VMAppExtension を使用して VM アプリケーションをデプロイ、監視、管理します。 そのため、デプロイされた VM アプリケーションのプロビジョニング状態は、VMAppExtension の状態で記述されます。
VM アプリケーションの状態を表示するには、[設定] の [ 拡張機能とアプリケーション ] タブに移動し、VMAppExtension の状態を確認します。
VM アプリケーションの状態を示すスクリーンショット。
Virtual Machine Scale Setsの VM アプリケーションの状態を表示するには、Azure ポータルの Virtual Machine Scale Sets ページに移動します。 [インスタンス] セクションで、いずれかのインスタンスを選択します。 次に、[設定] の [ 拡張機能とアプリケーション ] タブに移動し、 VMAppExtension の状態を確認します。
VM アプリケーションが VM にインストールされていない場合、値は空です。
VM インスタンス ビューの結果を取得するには:
GET
/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VMName}/instanceView?api-version=2024-03-03
結果は次のようになります。
{
...
"extensions" [
...
{
"name": "VMAppExtension",
"type": "Microsoft.CPlat.Core.VMApplicationManagerLinux",
"typeHandlerVersion": "1.0.9",
"statuses": [
{
"code": "ProvisioningState/succeeded",
"level": "Info",
"displayStatus": "Provisioning succeeded",
"message": "Enable succeeded: {\n \"CurrentState\": [\n {\n \"applicationName\": \"doNothingLinux\",\n \"version\": \"1.0.0\",\n \"result\": \"Install SUCCESS\"\n },\n {
\n \"applicationName\": \"badapplinux\",\n \"version\": \"1.0.0\",\n \"result\": \"Install FAILED Error executing command \u0027exit 1\u0027: command terminated with exit status=1\"\n }\n ],\n \"ActionsPerformed\": []\n}
"
}
]
}
...
]
}
VM アプリの状態は、インスタンス ビューの VM アプリ拡張機能の結果のステータス メッセージにあります。
Virtual Machine Scale Setsでアプリケーションの状態を取得するには:
GET
/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/ virtualMachineScaleSets/{VMSSName}/virtualMachines/{instanceId}/instanceView?api-version=2019-03-01
出力は、前の VM の例に似ています。
VM 上のアプリケーションのデプロイ状態を確認するには、 'az vm get-instance-view' を使用します。
az vm get-instance-view -g myResourceGroup -n myVM --query "instanceView.extensions[?name == 'VMAppExtension']"
Virtual Machine Scale Setsでアプリケーションのデプロイ状態を確認するには、'az vmss get-instance-view' を使用します。
az vmss get-instance-view --ids (az vmss list-instances -g myResourceGroup -n myVmss --query "[*].id" -o tsv) --query "[*].extensions[?name == 'VMAppExtension']"
Azure VM にデプロイされた VM アプリケーションのプロビジョニング状態を表示するには、Get-AzVM コマンドを使用します。
$rgName = "myResourceGroup"
$vmName = "myVM"
$result = Get-AzVM -ResourceGroupName $rgName -VMName $vmName -Status
$result.Extensions | Where-Object {$_.Name -eq "VMAppExtension"} | ConvertTo-Json
Virtual Machine Scale Setsにデプロイされた VM アプリケーションのプロビジョニング状態を表示するには、Get-AzVMSS コマンドを使用します。
$rgName = "myResourceGroup"
$vmssName = "myVMss"
$result = Get-AzVmssVM -ResourceGroupName $rgName -VMScaleSetName $vmssName -InstanceView
$resultSummary = New-Object System.Collections.ArrayList
$result | ForEach-Object {
$res = @{ instanceId = $_.InstanceId; vmappStatus = $_.InstanceView.Extensions | Where-Object {$_.Name -eq "VMAppExtension"}}
$resultSummary.Add($res) | Out-Null
}
$resultSummary | ConvertTo-Json -Depth 5
[実行] コマンドを使用してアプリケーションのインストールのログを表示する
AZURE VM アプリケーションは、Azure VM またはVirtual Machine Scale Setsにアプリケーションをダウンロードしてインストールすると、すべての stdout 結果をパイプして、アプリケーション リポジトリ内の stdout ファイルに送られます。 お客様は、アプリケーションのインストールに対して詳細ログを有効にし、特定のツールを使用してカスタム ログを書き込むことができます。 その後、お客様は と ファイルを手動で確認するか、Runcommand を使用してファイルの内容を取得できます。
マネージド実行コマンドで次の PowerShell スクリプトを使用します。 アプリケーションの <変数1> と <変数2> を更新する
$appName = "vm-application-name" # VM Application definition name
$appVersion = "1.0.0" # VM Application version name
$VMAppManagerVersion = "1.0.16" # Version of the VMApplicationManagerWindows extension on the VM
$StdoutFilePath = "C:\Packages\Plugins\Microsoft.CPlat.Core.VMApplicationManagerWindows\$VMAppManagerVersion\Downloads\$appName\$appVersion\stdout"
$StderrFilePath = "C:\Packages\Plugins\Microsoft.CPlat.Core.VMApplicationManagerWindows\$VMAppManagerVersion\Downloads\$appName\$appVersion\stderr"
Write-Host "`n=== Contents of stdout ==="
Get-Content -Path $StdoutFilePath
Write-Host "`n=== Contents of stderr ==="
Get-Content -Path $StderrFilePath
appName="vm-application-name" # VM Application definition name
appVersion="1.0.0" # VM Application version name
stdoutFilePath="/var/lib/waagent/Microsoft.CPlat.Core.VMApplicationManagerLinux/$appName/$appVersion/stdout"
stderrFilePath="/var/lib/waagent/Microsoft.CPlat.Core.VMApplicationManagerLinux/$appName/$appVersion/stderr"
printf "=== Contents of stdout ===\n%s \n" "$(cat $stdoutFilePath)"
printf '=== Contents of stderr ===\n%s \n' "$(cat $stderrFilePath)"
スクリプトを使用して実行コマンドを実行し、アプリケーションのインストール ログを取得します。
-
Azure ポータルを開き、VM に移動します。
- [ 操作] で、[ コマンドの実行] を選択します。
- 一覧から [RunPowerShellScript ] を選択します。
- エディターで PowerShell スクリプトを入力します。
- [ 実行 ] を選択してスクリプトを実行します。
- 出力セクションで出力を表示します。 スクリプトが失敗した場合は、[ エラー ] セクションで詳細を確認してください。
詳細については、「 Run Commandを参照してください。
オプション 1: アクション実行コマンドを使用する:
rgName="myResourceGroup"
vmName="myVM"
az vm run-command invoke \
--resource-group myResourceGroup \
--name myVm \
--command-id RunShellScript \
--scripts @./path/to/script.sh
VM でローカル スクリプトを 実行するアクション実行コマンド の詳細について説明します。
オプション 2: マネージド実行コマンドを使用する:
rgName="myResourceGroup"
vmName="myVM"
subId="mySubscriptionId"
vmLocation="myVMLocation"
az vm run-command create \
--name view-vmapp-install-logs \
--vm-name $vmName \
--resource-group $rgName \
--subscription $subId \
--location $vmLocation \
--script @.\path\to\script.sh \
--timeout-in-seconds 600
az vm run-command show \
--name view-vmapp-install-logs \
--vm-name $vmName \
--resource-group $rgName \
--subscription $subId \
--instance-view
VM でスクリプトを 実行するマネージド実行コマンド の詳細について説明します。
オプション 1: アクション実行コマンドの使用
$rgName = "myResourceGroup"
$vmName = "myVM"
$scriptPath = ".\path\to\script.ps1"
$result = Invoke-AzVMRunCommand `
-ResourceGroupName $rgName `
-Name $vmName `
-CommandId "RunPowerShellScript" `
-ScriptPath $scriptPath
$result.Value[0].Message
VM でローカル PowerShell スクリプトを実行する アクション実行コマンド の詳細について説明します。
オプション 2: マネージド実行を使用する
$rgName = "myResourceGroup"
$vmName = "myVM"
$runCommandName = "GetInstallLogsRunCommand"
$vmlocation = "myVMLocation"
Set-AzVMRunCommand `
-ResourceGroupName $rgName `
-VMName $vmName `
-RunCommandName $runCommandName `
-Location $vmLocation `
-SourceScript $(Get-Content -Path "./GetInstallLogs.ps1" -Raw)
$result = Get-AzVMRunCommand `
-ResourceGroupName $rgName `
-VMName $vmName `
-RunCommandName $runCommandName `
-Expand InstanceView
$result.InstanceView
VM でローカル PowerShell スクリプトを実行する マネージド実行コマンド の詳細について説明します。
Azure Resource Graphを使用してデプロイされたすべての VM アプリケーションを表示する
Azure リソース グラフ クエリを使用すると、デプロイされたすべての VM アプリケーションとそのプロパティをすべての VM とVirtual Machine Scale Setsにわたって表示できます。 アプリケーション インベントリ、状態、およびデプロイされたバージョンを大規模に表示するプログラムによる方法が提供されます。 ダッシュボードやカスタム レポートと統合する場合は、この方法を使用します。
resources
| where type == "microsoft.compute/virtualmachines" or type == "microsoft.compute/virtualmachinescalesets"
| where properties has "applicationProfile"
| extend resourceType = iff(type == "microsoft.compute/virtualmachines", "VM", "VMSS")
| extend applications = iff(resourceType == "VM", parse_json(properties["applicationProfile"]["galleryApplications"]), parse_json(properties["virtualMachineProfile"]["applicationProfile"]["galleryApplications"]))
| mv-expand applications
| extend enableAutomaticUpgrade = applications["enableAutomaticUpgrade"]
| extend packageReferenceId = applications["packageReferenceId"]
| extend treatFailureAsDeploymentFailure = applications["treatFailureAsDeploymentFailure"]
| parse packageReferenceId with "/subscriptions/" publisherSubcriptionId "/resourceGroups/" publisherResourceGroup "/providers/Microsoft.Compute/galleries/" galleryName "/applications/" appName "/versions/" version
| project tenantId, subscriptionId, resourceGroup, resourceName = name, type, location, appName, version, enableAutomaticUpgrade, treatFailureAsDeploymentFailure, galleryName, publisherSubcriptionId, publisherResourceGroup, properties
Azure Policyを使用して必要な VM アプリケーションを監査する
Azure Policyは、必要な VM アプリケーションが VM とVirtual Machine Scale Setsにデプロイされているかどうかを監査することで、ガバナンスを適用するのに役立ちます。 カスタム ポリシーを作成して割り当ててコンプライアンスを確認し、特定のアプリケーションがインフラストラクチャに存在することを確認できます。
Azure Policyを使用して VM アプリケーションのデプロイを監査する手順については、「audit required VM applications using Azure Policy」を参照してください。
デプロイされた VM アプリケーションを更新する
デプロイされた VM アプリケーションを更新するには、 を変更して新しいバージョンを参照するか、 や などのデプロイ設定を変更します。
1 つの VM で VM アプリケーションのバージョンまたは設定を更新します。
PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2024-03-03
Body
{
"properties": {
"applicationProfile": {
"galleryApplications": [
{
"packageReferenceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{applicationName}/versions/{newVersion}",
"treatFailureAsDeploymentFailure": true,
"enableAutomaticUpgrade": true
}
]
}
}
}
Virtual Machine Scale Sets (モデル) における VM アプリケーションの更新:
PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}?api-version=2024-03-03
Body
{
"properties": {
"virtualMachineProfile": {
"applicationProfile": {
"galleryApplications": [
{
"packageReferenceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{applicationName}/versions/{newVersion | latest}",
"treatFailureAsDeploymentFailure": true,
"order": 2
}
]
}
}
}
}
既存のVirtual Machine Scale Sets インスタンスに変更を適用します (upgradePolicy.mode が Manual の場合に必要)。
POST
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}/updateInstances?api-version=2024-03-03
Body
{
"instanceIds": ["*"]
}
1 つの VM 上の VM アプリケーションを更新します。
az vm application set \
--resource-group myResourceGroup \
--name myVM \
--app-version-ids /subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/myGallery/applications/myApp/versions/latest \
--treat-deployment-as-failure true
VM アプリケーションを Virtual Machine Scale Sets モデルで更新:
az vmss application set \
--resource-group myResourceGroup \
--name myVMss \
--app-version-ids /subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/galleries/myGallery/applications/myApp/versions/latest \
--treat-deployment-as-failure true
既存のVirtual Machine Scale Sets インスタンスに変更を適用します (upgradeMode が手動に設定されている場合)。
az vmss update-instances -g myResourceGroup -n myVMss --instance-ids "*"
1 つの VM 上の VM アプリケーションを更新します。
$rgName = "myResourceGroup"
$vmName = "myVM"
$galleryName = "myGallery"
$applicationName = "myApp"
$newVersion = "latest"
$vm = Get-AzVM -ResourceGroupName $rgName -Name $vmName
$appVersion = Get-AzGalleryApplicationVersion `
-ResourceGroupName $rgName `
-GalleryName $galleryName `
-GalleryApplicationName $applicationName `
-Name $newVersion
$packageId = $appVersion.Id
$app = New-AzVmGalleryApplication -PackageReferenceId $packageId -TreatFailureAsDeploymentFailure
$vm.ApplicationProfile.GalleryApplications = @($app)
Update-AzVM -ResourceGroupName $rgName -VM $vm
Virtual Machine Scale Sets (モデル) での VM アプリケーションの更新):
$rgName = "myResourceGroup"
$vmssName = "myVMss"
$galleryName = "myGallery"
$applicationName = "myApp"
$newVersion = "latest"
$vmss = Get-AzVmss -ResourceGroupName $rgName -VMScaleSetName $vmssName
$appVersion = Get-AzGalleryApplicationVersion `
-ResourceGroupName $rgName `
-GalleryName $galleryName `
-GalleryApplicationName $applicationName `
-Name $newVersion
$packageId = $appVersion.Id
$app = New-AzVmssGalleryApplication -PackageReferenceId $packageId -TreatFailureAsDeploymentFailure
$vmss.VirtualMachineProfile.ApplicationProfile.GalleryApplications = @($app)
Update-AzVmss -ResourceGroupName $rgName -VMScaleSetName $vmssName -VirtualMachineScaleSet $vmss
既存の VMSS インスタンスに変更を適用します (upgradeMode が Manual に設定されている場合)。
$instanceIds = (Get-AzVmssVM -ResourceGroupName $rgName -VMScaleSetName $vmssName).InstanceId
Update-AzVmssInstance -ResourceGroupName $rgName -VMScaleSetName $vmssName -InstanceId $instanceIds
ヒント
のバージョン識別子として を使用して、手動でデプロイを更新することなく、最新の発行済みバージョンを自動的にデプロイします。
Azure VM または仮想マシンスケールセットから VM アプリケーションを削除する
- Azure ポータルを開き、ターゲット仮想マシン (VM) またはVirtual Machine Scale Setsに移動します。
- [設定] で、[ 拡張機能とアプリケーション] を選択し、[ VM アプリケーション ] タブを選択します。
- VM アプリケーションの [アンインストール] ボタンをクリックし、[保存] をクリックします。
- [通知] で進行状況を追跡するか、VMAppExtension 状態の [インスタンス] ビューを確認します。
VM から VM アプリケーションをアンインストールする方法を示すスクリーンショット。
VM アプリケーションを削除するには、ターゲット アプリケーションをクリアまたは除外して を更新します。
1 つの VM から削除します。
PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2024-03-03
Body
{
"properties": {
"applicationProfile": {
"galleryApplications": []
}
}
}
Virtual Machine Scale Sets (モデル) から削除する:
PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}?api-version=2024-03-03
Body
{
"properties": {
"virtualMachineProfile": {
"applicationProfile": {
"galleryApplications": []
}
}
}
}
既存のVirtual Machine Scale Sets インスタンスに変更を適用します (upgradePolicy.mode が Manual の場合に必要)。
POST
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}/updateInstances?api-version=2024-03-03
Body
{
"instanceIds": ["0", "1"]
}
1 つの VM から削除します。
az vm update -g myResourceGroup -n myVM --set "properties.applicationProfile.galleryApplications=[]"
Virtual Machine スケール セット (モデル) から削除する。
az vmss update -g myResourceGroup -n myVMss --set "virtualMachineProfile.applicationProfile.galleryApplications=[]"
既存の VMSS インスタンスに変更を適用します (手動アップグレード ポリシー):
az vmss update-instances -g myResourceGroup -n myVMss --instance-ids "*"
1 つの VM から削除します。
$rgName = "myResourceGroup"
$vmName = "myVM"
$vm = Get-AzVM -ResourceGroupName $rgName -Name $vmName
$vm.ApplicationProfile.GalleryApplications = @()
Update-AzVM -ResourceGroupName $rgName -VM $vm
Virtual Machine Scale Sets (モデル) から削除し、各インスタンスに適用する:
$rgName = "myResourceGroup"
$vmssName = "myVMss"
$vmss = Get-AzVmss -ResourceGroupName $rgName -VMScaleSetName $vmssName
$vmss.VirtualMachineProfile.ApplicationProfile.GalleryApplications = @()
Update-AzVmss -ResourceGroupName $rgName -VMScaleSetName $vmssName -VirtualMachineScaleSet $vmss
$instanceIds = (Get-AzVmssVM -ResourceGroupName $rgName -VMScaleSetName $vmssName).InstanceId
Update-AzVmssInstance -ResourceGroupName $rgName -VMScaleSetName $vmssName -InstanceId $instanceIds
次のステップ