Vagrant | Vagrant-AWS Provider で AWS に CoreOS 環境を構築する #vagrant #coreos
概要
Vagrant-AWS Provider で AWS に CoreOS 環境を構築します
手順
Vagrant AWS Plugin のインストール
$ vagrant plugin install vagrant-aws
Installing the 'vagrant-aws' plugin. This can take a few minutes...
$ vagrant plugin list | grep aws
vagrant-aws (0.5.0)
Vagrant Dotenv Plugin のインストール (環境変数の管理に利用)
$ vagrant plugin install dotenv
Installing the 'dotenv' plugin. This can take a few minutes...
Installed the plugin 'dotenv (1.0.2)'!
$ vagrant plugin list | grep dotenv
dotenv (1.0.2)
dummy の Vagrant Box を取得する
$ vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
$ vagrant box list | grep dummy
dummy (aws, 0)
Vagrantfile を編集する
- Vagrantfile の生成
$ vagrant init -m
$ ls -F | grep Vagrantfile
Vagrantfile*
- Vagrantfile の編集
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "dummy"
Dotenv.load
config.vm.provider :aws do |aws, override|
aws.access_key_id = ENV['ACCESS_KEY_ID']
aws.secret_access_key = ENV['SECRET_ACCESS_KEY']
aws.keypair_name = ENV['KEY_PAIR_NAME']
aws.region = "ap-northeast-1"
aws.ami = 'ami-858eb884'
aws.instance_type = 't1.micro'
aws.security_groups = 'your_security_group'
override.ssh.username = "core"
override.ssh.private_key_path = "/path/to/your_key_pair_name.pem"
end
end
.env に環境変数を設定
- .env ファイルを作成
touch .env
AWS_ACCESS_KEY_ID=your access key id
AWS_SECRET_ACCESS_KEY=your secret access key
KEY_PAIR_NAME=your_key_pair_name
VM の起動
$ vagrant up --provider=aws
# Windows + Cygwin の場合(exeを付けないとエラーが発生)
# $ vagrant.exe up --provider=aws
# 問題発生時は debug オプションを利用
# $ vagrant.exe up --provider=aws --debug
※ ssh で直接接続検証をする場合
ssh -i /path/to/your/key core@your_ip
SSH 接続
$ vagrant ssh
core@your_ip ~ $
core@your_ip ~ $ cat /etc/os-release
NAME=CoreOS
ID=coreos
VERSION=444.5.0
VERSION_ID=444.5.0
BUILD_ID=
PRETTY_NAME="CoreOS 444.5.0"
ANSI_COLOR="1;32"
HOME_URL="https://coreos.com/"
BUG_REPORT_URL="https://github.com/coreos/bugs/issues"
# Windows + Cygwin の場合(exeを付けないとエラーが発生)
# $ vagrant.exe ssh