Closed3

Packer でハマったところ

yumenomatayumeyumenomatayume

使用する OS イメージは CLI でインストールできるものを使用する

Packer から Ubuntu のイメージを作成している時、boot: 画面に遷移せず GUI でのインストールが始まってしまい、自動インストールできない事象が発生しました。

試したイメージは以下の2つです。

  • Ubuntu18.04
  • Ubuntu20.04

試しに Packer ではなく、手作業でやったら上手くいきました。

どうやら Packer を使用した場合、ESXi の起動が早すぎて Install Ubuntu(GUIインストール) が選択されてしまっているようでした。

VMware ISO - Builders | Packer by HashiCorp

boot_wait (duration string | ex: "1h5m2s") - The time to wait after booting the initial virtual machine before typing the boot_command. The value of this should be a duration. Examples are 5s and 1m30s which will cause Packer to wait five seconds and one minute 30 seconds, respectively. If this isn't specified, the default is 10s or 10 seconds. To set boot_wait to 0s, use a negative number, such as "-1s"

boot_wait (期間文字列 | 例: "1h5m2s") - 初期仮想マシンの起動後、boot_command を入力する前に待機する時間。 この値は期間でなければなりません。 たとえば、5 秒と 1 分 30 秒の場合、Packer はそれぞれ 5 秒と 1 分 30 秒待機します。 これが指定されていない場合、デフォルトは 10 秒または 10 秒です。 boot_wait を 0 に設定するには、「-1s」などの負の数を使用します。

Packer 公式ドキュメントに記載されている通り、boot_wait オプションを使用する事で、処理を待つ時間を指定する事ができます。

しかし、これを実施しても問題は解消せず、別の原因がありそうだったのでもう少し調査しました。

原因

Ubuntu で使用している iso ファイルを誤っていました。
Casper というイメージを使用していましたが、手動インストール専用?らしく自動インストールする時は Legacy な iso を使用する必要がありました。以下で公開されているものが Legacy なものになります。

http://cdimage.ubuntu.com/releases/

yumenomatayumeyumenomatayume

http_directory オプションとコマンド実行ディレクトリについて

ESXi 上に centos7 の VM を作成しているときに起きたエラーです。

kickstart を用いて OS インストールをしていましたが、以下の画面でハングってしまいエラーとなりました。

$ packer build packer/centos7.json 
centos7: output will be in this color.

==> centos7: Retrieving ISO
==> centos7: Trying ../packer_cache/e476ea1d3ef3c2e3966a7081ac4239cd5ae5e8a3.iso
==> centos7: Trying ../packer_cache/e476ea1d3ef3c2e3966a7081ac4239cd5ae5e8a3.iso?checksum=sha256%3A07b94e6b1a0b0260b94c83d6bb76b26bf7a310dc78d7a9c7432809fb9bc6194a
==> centos7: ../packer_cache/e476ea1d3ef3c2e3966a7081ac4239cd5ae5e8a3.iso?checksum=sha256%3A07b94e6b1a0b0260b94c83d6bb76b26bf7a310dc78d7a9c7432809fb9bc6194a => /Users/yukihisa/.ghq/github.com/ymmmtym/ansible-mgmt/packer_cache/e476ea1d3ef3c2e3966a7081ac4239cd5ae5e8a3.iso
==> centos7: Configuring output and export directories...
==> centos7: Remote cache was verified skipping remote upload...
==> centos7: Creating required virtual machine disks
==> centos7: Building and writing VMX file
==> centos7: Starting HTTP server on port 8106
==> centos7: Registering remote VM...
==> centos7: Starting virtual machine...
==> centos7: Connecting to VNC over websocket...
==> centos7: Waiting 10s for boot...
==> centos7: Typing the boot command over VNC...
==> centos7: Waiting for SSH to become available...

原因

ESXi のコンソールで中を覗いてみると、以下のようになっていました。

dracut-error-tail

dracut error curl

curl で 404 エラーが発生していました。よく見ると kickstart ファイルが取得できていないことが原因でした。

解消方法

コマンド実行時のディレクトリが Web サーバの root ディレクトリになるようです。つまりファイルから見た相対パスではなく、実行ディレクトリから見た相対パスを記載する必要がありました。

Packer 実行中は、任意のポートが http server として使用されますので、実際に以下のように確認する事ができます。

$ curl localhost:8106
<pre>
<a href="packer/">packer/</a>
<a href="packer_cache/">packer_cache/</a>
</pre>
yumenomatayumeyumenomatayume

その他

  • Ctrl + c でコマンド終了させたら、作成中の VM も削除されました。packer のデフォルトの仕様であり、error が発生した場合は作成中の image は削除します。
  • Packerで仮想マシンにvnc接続しようとすると、${IP}:0 ポートになりエラーなってしまう場合があるので、フロッピーにマウントする形式に変更しました。
このスクラップは2022/04/26にクローズされました