広告

Azure Arc enable Server コマンド実行

Arc

コマンド実行機能は Azure VM で以前から実装された機能で、Azure Portal の GUI で VM の OS 内にコマンドをインジェクションして、実行させる機能です。

現在 Azure Arc enable Server でもこの機能が利用できるようになりましたが、まだプレビュー段階となったため、まだ不完全な状態です。
現時点(2025/8/4)では、Azure Portal の GUI では直接実行できず、Powershell や Azcli のコマンドを使って、コマンドを実行させる必要があります。

今回の内容は、実行する際のコマンド サンプルをご紹介します。

サンプルコード

# Azcli インストールしていない場合、下記のリンクを参照してインストールしてください。
# 参考:https://learn.microsoft.com/ja-jp/cli/azure/install-azure-cli-windows?view=azure-cli-latest&pivots=msi

# プレビューコマンドを利用するための対応
# 参考:https://github.com/Azure/azure-cli-extensions/issues/8151
az extension add --name connectedmachine --version 1.1.0 --allow-preview

# Azure へ Login(今回はデバイス認証オプションを利用)
az login --use-device-code

# コマンド実行機能で、Azure Arc enable VM にコマンドを実行させる
# hostname コマンドを実行する例
az connectedmachine run-command create --name "myRunCommand" --machine-name "arcServerName" --resource-group "arcServerRG" --script "hostname"

# すべての「コマンド実行」の結果をリストする
az connectedmachine run-command list --machine-name "arcServerName" --resource-group "arcServerRG"

# 指定の「コマンド実行」の結果確認
az connectedmachine run-command show --name "myRunCommand" --machine-name "arcServerName" --resource-group "arcServerRG"

この機能を利用して、Arc enable VM の外からコマンドを実行させることができます。
また、Azure Automation など自動化するサービスと併用することで、自動化の幅も広がると思います。

参考情報

コメント

タイトルとURLをコピーしました