Be warned when deploying with capistrano

In Edicy, we're using capistrano-multistage gem to make software updates to testing, staging and production environments. Kinda standard. SSH Authentication to all these environments is being done with ssh keys and this way it is quite easy to mistakenly type "cap production deploy" when you actually meant "cap staging deploy". So we added few extra lines to our production environment file to ask for a confirmation before doing anything in live app servers.

In config/deploy/production.rb file we have

set(:confirmed) do
  puts <<-WARN
    WARNING: You're about to perform actions on production server(s)
    Please confirm that all your intentions are kind and friendly
  answer = Capistrano::CLI.ui.ask "  Are you sure you want to continue? (Y) "
  if answer == 'Y' then true else false end

after 'multistage:ensure' do
  unless confirmed
    puts "\nDeploy cancelled!"

Checking the confirmation status in after 'multistage:ensure' hook is not the most beautiful place to have it, but it works.