Capistrano local and remote prompt handling

Gary McGhee - Thursday, October 16, 2008
This is one of those things that I've wanted to figure out but never have in Capistrano (2.5)
It does both prompting the local user for a value, and fulfilling the remote machines prompt for a value.
I love Capistrano even more now !

# give block with |aText,aStream,aState| that returns response or nil
def run_respond(aCommand)
 run(aCommand) do |ch,stream,text|
  ch[:state] ||= { :channel => ch }
  output = yield(text,stream,ch[:state])
  ch.send_data(output) if output
 end
end

task :dump_db_svn do

  # just dumps db to a file in a svn dir
  run "mysqldump --user=root --password=nottelling --databases --add-drop-database joomla_db > /root/joomla_db_snapshot/joomla_db.sql"

  # svn is using ssh+svn, so prompts for a passphrase (on the remote machine)
  run_respond 'ssh-add somekey.ppk; svn commit /root/joomla_db_snapshot -m "latest joomla_db"' do |text,stream,state|
  case text
  when /Enter passphrase/ then 
  Capistrano::CLI.password_prompt(text)+"\n" # this prompts the local user with the remote prompt text, then returns the result
  end  
  end

end

Comments
Post has no comments.
Post a Comment




Captcha Image

Trackback Link
http://www.buzzware.com.au/BlogRetrieve.aspx?BlogID=1956&PostID=28848&A=Trackback
Trackbacks
Post has no trackbacks.