LoginSignup
8
8

More than 5 years have passed since last update.

Vagrant1.5でEC2インスタンスを立ち上げる設定

Last updated at Posted at 2014-05-15

VagrantからEC2インスタンスにsshした後、プロビジョニングする設定。

やったこと

プラグインインストール

$ vagrant plugin install vagrant-aws

box追加

$ vagrant box add aws https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box

vagrant init

$ vagrant init aws

VagrantFile

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "aws"

  config.vm.provider :aws do |aws, override|
    aws.access_key_id     = "<ACCESS_KEY_ID>"
    aws.secret_access_key = "<SECRET_ACCESS_KEY>"
    aws.keypair_name = "<KEYPAIR_NAME>"
    aws.instance_type = "t1.micro"
    aws.region = "ap-northeast-1"
    aws.ami = "<AMI>"
    aws.security_groups = [ '<SECURITY_GROUPS>' ] 

    override.ssh.username = "ec2-user"
    override.ssh.private_key_path = "~/.ssh/aws.pem"

  end

end

vagrant up

$ VAGRANT_LOG=DEBUG vagrant up --provider=aws

デバッグつけるとこけた時に便利

vagrant ssh

$ vagrant ssh

       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2014.03-release-notes/
1 package(s) needed for security, out of 18 available
Run "sudo yum update" to apply all updates.

プロビジョニング

立ちあげた後なんだけど、プロビジョニングも普通に追記すればおk。
provisionの内容はこんな感じで。

config.vm.provision :fabric do |fabric|
  fabric.fabfile_path = "./provision.py"
  fabric.tasks = ["execute"]
end

これを追記してprovision実行

$ vagrant provision

トラブルシューティング

$ vagrant provision

の際、こんなエラーが出たら…

Fatal error: sudo() received nonzero return code 2 while executing!

/etc/sudoersの下記をコメントアウト

Defaults requiretty

Secret Access Keyについて

あとSecret Access Keyの取得方法がよりセキュアになったみたいで、IAMマネジメントのコンソールから取得するようだ。

参考

Secret Access Keyは取得直後の一度しか表示されない。

8
8
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
8
8