LoginSignup
4
4

More than 5 years have passed since last update.

play frameworkのプロジェクトをchefで作成

Posted at

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
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4