Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby -KU
- require 'rubygems'
- require 'vlad'
- # I use multiple ssh keys to manage multiple servers
- # I do this using ssh's -i option to point to the
- # identity (private key) I want to use for authentication
- # It seems, for some reason, Vlad's run command mangles
- # the path arg to ssh -i <path>
- # setup for system call and key gen
- pwd = Dir.pwd
- domain = "localhost"
- key = "#{pwd}/tmp_dir/tmp_key"
- # We want the SSH call to fail fast so we send it to port 42
- ssh_flags = ["-i #{key}", "-p 42"]
- # setup vlad the same way as system
- set :domain, domain
- set :ssh_flags, ssh_flags
- # Generate a new SSH key pair in a directory which is chmod 700 (req'd by ssh)
- system "mkdir -p #{pwd}/tmp_dir;chmod 700 #{pwd}/tmp_dir"
- system "ssh-keygen -P \"\" -t dsa -f #{key}"
- # setup vlad's remote_task
- remote_task :ssh_err, :roles => :app do
- begin
- run "echo a"
- rescue Vlad::CommandFailedError => e
- # I know it will fail (unless you're running ssh on port 42)
- # The interesting thing is in the return from run
- end
- end
- puts "Just to be sure, File.exists?: #{File.exists? key}\n\n"
- puts 'COMMENT: Here no warnings, ssh finds the key fine'
- system "ssh #{ssh_flags.join' '} #{domain}"
- puts "\n"
- puts "COMMENT: Why the warning? We're using the same absolute path."
- Rake::Task['ssh_err'].invoke
- # _________________ OUTPUT ______________
- # ...
- # Just to be sure, File.exists?: true
- #
- # COMMENT: Here no warnings, ssh finds the key fine
- # ssh: connect to host localhost port 42: Connection refused
- #
- # COMMENT: Why the warning? We're using the same absolute path.
- # Warning: Identity file /Users/nihildeb/tmp_dir/tmp_key not accessible: No such file or directory.
- # ssh: connect to host localhost port 42: Connection refused
Add Comment
Please, Sign In to add comment