Vagrant でホストされているローカル Ubuntu サーバーをデプロイし、それを Azure Arc に接続する

この記事では、Vagrant を使用してローカルの Ubuntu 仮想マシンをデプロイし、それを 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 サブスクリプションとリソース グループに限定することを強くお勧めします。

  5. Vagrant ファイルは、必要なすべてのアーティファクトをインストールするため、そして環境変数を挿入するためのスクリプトを VM OS 上で実行します。 scripts/vars.sh シェル スクリプトを、作成した Azure サービス プリンシパルに合わせて編集します。

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

デプロイ

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

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

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

A screenshot of the vagrant up command.

ダウンロードが完了すると、プロビジョニングが始まります。 次のスクリーンショットに示すように、プロセスは 3 分以内に完了します。

A screenshot of a completed vagrant up command.

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

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

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

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

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

Another screenshot of the vagrant up command.

実際の登録プロセスをデモンストレーションまたはコントロールする場合は、次の手順を行います。

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

    A screenshot of the azcmagent connect command.

    A screenshot of the az group create command.

  2. vagrant ssh コマンドを使用して VM に SSH 接続します。

    A screenshot of an SSH key connecting to the Vagrant machine.

  3. 環境変数を使用して、コメント アウトした同じ azcmagent connect コマンドを実行します。

    Another screenshot of the azcmagent connect command.

デプロイの削除

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

A screenshot of the vagrant destroy command.