Vagrant によってホストされるローカルの Windows Server インスタンスをデプロイして Azure Arc に接続する

次の記事では、Vagrant を使用してローカルの Windows 10 仮想マシンをデプロイし、それを Azure Arc 対応サーバー リソースとして接続するためのガイダンスを提供します。

前提条件

  1. Azure Arc Jumpstart リポジトリを複製します。

    git clone https://github.com/microsoft/azure_arc.git
    
  2. バージョン 2.7 以降の Azure CLI をインストールするか、更新します。 現在インストールされているバージョンを確認するには、次のコマンドを使用してください。

    az --version
    
  3. Vagrant は、基になるハイパーバイザーに依存しています。 このガイドでは、Oracle VM VirtualBox を使用します。

    1. VirtualBox をインストールします。

    2. Vagrant をインストールします。

  4. Azure サービス プリンシパルを作成します。

    Vagrant 仮想マシンを Azure Arc に接続するには、共同作成者ロールが割り当てられた Azure サービス プリンシパルが必要です。 これを作成するには、自分の Azure アカウントにサインインして、次のコマンドを実行します。 このコマンドは、Azure Cloud Shell 内で実行することもできます。

    az login
    az account set -s <Your Subscription ID>
    az ad sp create-for-rbac -n "<Unique SP Name>" --role contributor --scopes "/subscriptions/<Your Subscription ID>"
    

    次に例を示します。

    az ad sp create-for-rbac -n "http://AzureArcServers" --role contributor --scopes "/subscriptions/00000000-0000-0000-0000-000000000000"
    

    出力は次のようになります。

    {
      "appId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "displayName": "http://AzureArcServers",
      "password": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "tenant": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    }
    

    注意

    サービス プリンシパルのスコープを、特定の Azure サブスクリプションとリソース グループに設定することを強くお勧めします。

  • vagrantfile は、必要なすべての成果物をインストールし、環境変数を挿入するためのスクリプトを VM OS 上で実行します。 scripts/vars.ps1 PowerShell スクリプトを、作成した Azure サービス プリンシパルに合わせて編集します。

    • subscriptionId = お使いの Azure サブスクリプション ID
    • appId = お使いの Azure サービス プリンシパル名
    • password = お使いの Azure サービス プリンシパル パスワード
    • tenantId = お使いの Azure テナント ID
    • resourceGroup = Azure リソース グループ名
    • location = Azure リージョン

デプロイ

Vagrant のすべてのデプロイと同様に、vagrantfileVagrant box が必要です。 大まかに、デプロイでは以下が行われます。

  • Windows 10 イメージ ファイル Vagrant box ダウンロードする
  • Azure Arc インストール スクリプトを実行する

scripts/vars.ps1 スクリプトをお使いの環境に合わせて編集した後で、Vagrantfile フォルダーから vagrant up を実行します。 今回 VM を初めて作成するため、この最初の実行では、その後に実行する場合よりはるかに時間がかかります。 これは、デプロイによって Windows 10 ボックスが初めてダウンロードされるためです。

A screenshot of running the vagrant up command.

ダウンロードが完了すると、実際のプロビジョニングが開始します。 次のスクリーンショットに示されているように、このプロセスには 7~10 分かかります。

A screenshot of a completed vagrant up command.

注意

証明書の失効確認に関するエラーが表示された場合は、この構成を Vagrantfile に追加します。

config.vm.box_download_insecure = true

完了すると、新しいリソース グループ内の新しい Azure Arc 対応サーバーとして接続された Windows 10 VM がローカルにデプロイされます。

A screenshot of an Azure Arc-enabled server in the Azure portal.

A screenshot of the details from an Azure Arc-enabled server in the Azure portal.

半自動デプロイ (省略可能)

実行の最後の手順では、VM を新しい Azure Arc 対応サーバー リソースとして登録します。

Another screenshot of a completed vagrant up command.

実際の登録プロセスのデモまたは制御を行う場合は、次の手順を行います。

  1. install_arc_agent PowerShell スクリプトで、run connect command セクションをコメント アウトしてファイルを保存します。 リソース グループの作成をコメント アウトまたは変更することもできます。

    A screenshot of the install_arc_agent PowerShell script.

    A screenshot of the az group create command.

  2. vagrant rdp コマンドを使用して VM を RDP 接続します。 vagrant/vagrant をユーザー名/パスワードとして使用します。

    A screenshot of accessing a Vagrant server with the Microsoft Remote Desktop Protocol.

  3. PowerShell ISE を管理者として開き、C:\runtime\vars.ps1 ファイルを環境変数で編集します。

    A screenshot of Windows PowerShell ISE.

  4. Invoke-Expression C:\runtime\vars.ps1 コマンド、az group create --location $env:location --name $env:resourceGroup --subscription $env:subscriptionId コマンド、azcmagent connect コマンドを貼り付けて、スクリプトを実行します。

    A screenshot of PowerShell ISE running a script.

デプロイの削除

デプロイ全体を削除するには、vagrant destroy -f コマンドを実行します。 vagrantfile には、実際の VM を破棄する前に Azure リソース グループを削除するコマンドを実行する before: destroy Vagrant トリガーが含まれています。

A screenshot of the vagrant destroy command.