Guest User

Untitled

a guest
Jul 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. #!/usr/bin/env ruby -KU
  2. require 'rubygems'
  3. require 'vlad'
  4.  
  5. # I use multiple ssh keys to manage multiple servers
  6. # I do this using ssh's -i option to point to the
  7. # identity (private key) I want to use for authentication
  8. # It seems, for some reason, Vlad's run command mangles
  9. # the path arg to ssh -i <path>
  10.  
  11. # setup for system call and key gen
  12. pwd = Dir.pwd
  13. domain = "localhost"
  14. key = "#{pwd}/tmp_dir/tmp_key"
  15. # We want the SSH call to fail fast so we send it to port 42
  16. ssh_flags = ["-i #{key}", "-p 42"]
  17.  
  18. # setup vlad the same way as system
  19. set :domain, domain
  20. set :ssh_flags, ssh_flags
  21.  
  22. # Generate a new SSH key pair in a directory which is chmod 700 (req'd by ssh)
  23. system "mkdir -p #{pwd}/tmp_dir;chmod 700 #{pwd}/tmp_dir"
  24. system "ssh-keygen -P \"\" -t dsa -f #{key}"
  25.  
  26. # setup vlad's remote_task
  27. remote_task :ssh_err, :roles => :app do
  28. begin
  29. run "echo a"
  30. rescue Vlad::CommandFailedError => e
  31. # I know it will fail (unless you're running ssh on port 42)
  32. # The interesting thing is in the return from run
  33. end
  34. end
  35.  
  36. puts "Just to be sure, File.exists?: #{File.exists? key}\n\n"
  37.  
  38. puts 'COMMENT: Here no warnings, ssh finds the key fine'
  39. system "ssh #{ssh_flags.join' '} #{domain}"
  40.  
  41. puts "\n"
  42.  
  43. puts "COMMENT: Why the warning? We're using the same absolute path."
  44. Rake::Task['ssh_err'].invoke
  45.  
  46. # _________________ OUTPUT ______________
  47. # ...
  48. # Just to be sure, File.exists?: true
  49. #
  50. # COMMENT: Here no warnings, ssh finds the key fine
  51. # ssh: connect to host localhost port 42: Connection refused
  52. #
  53. # COMMENT: Why the warning? We're using the same absolute path.
  54. # Warning: Identity file /Users/nihildeb/tmp_dir/tmp_key not accessible: No such file or directory.
  55. # ssh: connect to host localhost port 42: Connection refused
Add Comment
Please, Sign In to add comment