LoginSignup
3
4

More than 5 years have passed since last update.

Packer初心者がお送りするトラブルシューティング

Last updated at Posted at 2016-12-03

packerを触りたての時に発生したエラーを共有します。

インスタンスにt2.micro選んだらVPCなんちゃらって言われた

まずpackerを動かしてみたいから、VPC設定はなしにして
安いt2.microで実行してみよう!
→エラー

==> amazon-ebs: Error launching source instance: VPCResourceNotSpecified: The specified instance type can only be used in a VPC. A subnet ID or network interface ID is required to carry out the request.
==> amazon-ebs:     status code: 400, request id:

原因

t2系のインスタンスはVPC内でしか起動できない。
http://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/t2-instances.html

対策

t2系インスタンスを使いたいのであれば、packerでVPC内にインスタンスが作成できるように設定を行う。
VPC内にインスタンスを作る必要がないのであれば、VPC不要のインスタンスを選択。m3系とか。
http://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/using-vpc.html#vpc-only-instance-types

sudoできない旨のエラー

sudo: sorry, you must have a tty to run sudo

原因

ssh_ptyがfalseになっている。

対策

ssh_ptyの値は、デフォルトがfalseなので、packerの設定ファイルでtrueにする。
https://www.packer.io/docs/templates/communicator.html#ssh_pty

...
  "builders": {
    ...
    "ssh_pty": true
  }
}

コマンドラインでsudoしたらエラー

以下のように、コマンドライン上でsudoを行うと、

...
  "provisioners": [
    {
      "type": "shell",
      "inline": ["sudo echo foo"]
    }
  ]
}

きっと以下のエラーが出迎える。

sudo: sorry, you must have a tty to run sudo

原因

Defaults requirettyが有効になっている。

対策

/etc/sudoersのDefaults.requirettyをコメントアウトする。

...
  "provisioners": [
    {
      "type": "shell",
      "inline": ["sed -i -e 's/^\\(Defaults.*requiretty\\)/#\\1/' /etc/sudoers", "sudo echo foo"]
    }
  ]
}
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4