play frameworkのプロジェクトをchefで作成しようとすると、play new
でアプリケーションの名前を入力するよう求められるために詰まりました。
対策として、expect
を使用しました。
以下は、autoexpect
を使って生成したファイルです。
install_play.exp
#!/usr/bin/expect -f
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set timeout -1
spawn play new application_path
match_max 100000
expect -exact "What is the application name?"
send -- "application_name\r"
expect eof
これをchefのtemplates化。
install_play.exp.erb
#!/usr/bin/expect -f
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
set timeout -1
spawn play new <%= @application_path %>
match_max 100000
expect -exact "What is the application name?"
send -- "<%= @application_name %>\r"
expect eof
実行するレシピはこんな感じ。
playframework_app.rb
# アプリケーションディレクトリの作成
# expectを使用して、対話コマンドに対応
template "/tmp/install_play.exp" do
source "install_play.exp.erb"
mode "755"
owner node['playframework']['user']
group node['playframework']['group']
variables({
:application_path => node['playframework']['application']['path'],
:application_name => node['playframework']['application']['name']
})
end
bash "play new" do
creates "#{node['playframework']['application']['path']}"
user node['playframework']['user']
code <<-BASH
/tmp/install_play.exp
BASH
end