ItamaeのレシピをVagrantに流し込んで環境構築

Itamaeを使ってVagrantの環境構築をするためのgemとして、vagrant-itamaeというものを作ってくださってるようなので、これを使います。

https://github.com/chiastolite/vagrant-itamae

vagrantにpluginとしてインストールします。

$ vagrant plugin install vagrant-itamae

Vagrantfileに、以下のように追加します。

Vagrant.configure('2') do |config|

  # ...
  
  config.vm.provision :itamae do |config|
    config.sudo = true
    config.shell = "/bin/sh"
    config.recipes = ["./recipes/recipes/base.rb"]
    config.json = "./recipes/nodes/node.json"
  end
end

これであとは$ vagrant upすれば自動的にレシピが走ってくれます。ShellScriptでやってたのだけど、こっちの方がRubyで書けてメンテナブルだし、いろいろ使い回せるのでいい感じ。

一度以下のようなエラーで落ちてしまいました。

/path/to/itamae/itamae/backend.rb:181:in `build_command': undefined method `shellescape' for nil:NilClass (NoMethodError)

ググったら、ここで解決しました。ありがたや。。。

http://diary.hamaco.org/post/132007736029/vagrant-itamae-%E3%81%A7%E3%81%A1%E3%82%87%E3%81%A3%E3%81%A8%E3%81%AF%E3%81%BE%E3%81%A3%E3%81%9F