概要
Vagrantで作成した仮想環境にItamaeでrbenvをインストールする
開発環境を自動構築したいけど、Chefが手に余る感じ(勉強不足)なのでItamaeでやってみる
Vagrant
Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu-14.04"
config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-14.04_chef-provisionerless.box"
config.vm.network "private_network", ip: "192.168.33.109"
config.ssh.forward_agent = true
end
$ vagrant up
Gemfile
Gemfile
source 'https://rubygems.org'
gem 'rake'
gem 'serverspec'
gem 'itamae'
gem 'itamae-plugin-recipe-rtn_rbenv'
$ bundle install --path vendor/bundle
Itamaeでruby-2.2.0インストール
# recipes/ruby.rb
include_recipe 'rtn_rbenv::system'
# nodes/node.json
{
"rtn_rbenv": {
"user": "vagrant",
"versions": {
"2.2.0": []
},
"global": "2.2.0"
}
}
$ bundle exec itamae ssh -h 192.168.33.109 -u vagrant -j nodes/node.json recipes/ruby.rb -i .vagrant/machines/default/virtualbox/private_key
serverspec
$ bundle exec serverspec-init
spec/default/sample_spec.rb
require 'spec_helper'
describe command('source /etc/profile.d/rbenv.sh; which rbenv') do
let(:disable_sudo) { true }
its(:stdout) { should match %r{/usr/local/rbenv/bin/rbenv} }
end
$ bundle exec rake spec
rake aborted!
Circular dependency detected: TOP => spec => spec:all => spec:default => spec:all
Tasks: TOP => spec => spec:all => spec:default
(See full trace by running task with --trace)
# とりあえずRakefileの該当行をコメントアウト
# task :default => :all
$ bundle exec rake spec
#
# テストがこけます!
よく考えてみたらubuntuなのでsourceコマンドが効かない。
(何も考えず適当にrbenvのserverspecコピペしてたのが原因)
以下のように修正
spec/default/sample_spec.rb
require 'spec_helper'
describe command('. /etc/profile.d/rbenv.sh; which rbenv') do
let(:disable_sudo) { true }
its(:stdout) { should match %r{/usr/local/rbenv/bin/rbenv} }
end
これで通るはず