ChefでHubotをインストールする


コマンドラインでのインストールと同様のことをChefで行おうとしたときに、対話式の部分で躓いたのでそのときのメモ。
※Node.jsがインストールされている前提です。

コマンドラインでインストール

$npm install -g yo generator-hubot hubot coffee-script
$yo hubot

このときに対話式でいくつか入力を求められます。
Owner : 制作者のメールアドレス
Bot name : 生成するHubotの名前
Description : 生成するHubotの説明
Bot adapter : 使用するアダプタ

Chefでインストール

chefで対話式のインストーラを扱う場合はexpectと使うと自動入力してくれる。

cookbook_file "/tmp/yo_hubot.sh" do
  mode "755"
  source "your_directory/yo_hubot.sh"
end

execute "install hubot" do
  not_if "which hubot"
  command "npm install -g yo generator-hubot hubot coffee-script"
  notifies :run, "execute[yo_hubot]"
end

execute "yo_hubot" do
  action :nothing
  command "/tmp/yo_hubot.sh"
end
yo_hubot.sh
#!/bin/bash
expect -c '
spawn yo hubot
set timeout -1
expect {
  -regexp ".*Y/n.*" {
    exp_send "n\r"
    -regexp ".*Owner.*" {
      exp_send "your e-mail adress\r"
    }
  }
  -regexp ".*Owner.*" {
    exp_send "your e-mail adress\r"
  }
}
expect {
  -regexp ".*Bot name.*" {
    exp_send "your bot name\r"
  }
}
expect {
  -regexp ".*Description.*" {
    exp_send "your bot description\r"
  }
}
expect {
  -regexp ".*Bot adapter.*" {
    exp_send "use adapter name\r"
  }
}
expect eof
'

何か間違ってるとかこっちの方がいいとかありましたらお願いします。