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マネジメントのコンソールから取得するようだ。
参考
- Where’s my secret access key? - AWS Security Blog
- Getting Your Access Key ID and Secret Access Key - Amazon Simple Queue Service
Secret Access Keyは取得直後の一度しか表示されない。