mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
ssh_options
allow user set ssh_options per server
This commit is contained in:
parent
b7572cbef0
commit
391468e239
3 changed files with 65 additions and 0 deletions
|
@ -35,6 +35,12 @@ module Capistrano
|
|||
@properties ||= Properties.new
|
||||
end
|
||||
|
||||
def netssh_options_with_options
|
||||
@netssh_options ||= netssh_options_without_options.merge( fetch(:ssh_options) || {} )
|
||||
end
|
||||
alias_method :netssh_options_without_options, :netssh_options
|
||||
alias_method :netssh_options, :netssh_options_with_options
|
||||
|
||||
class Properties
|
||||
|
||||
def initialize
|
||||
|
|
|
@ -17,4 +17,18 @@ role :db, %w{deploy@example.com}
|
|||
# extended properties on the server.
|
||||
server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
|
||||
|
||||
# you can set custom ssh options
|
||||
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
|
||||
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
|
||||
# server 'example.com',
|
||||
# user: 'user_name',
|
||||
# roles: %w{web app},
|
||||
# ssh_options: {
|
||||
# user: 'user_name', # overrides user setting above
|
||||
# keys: %w(/home/user_name/.ssh/id_rsa),
|
||||
# forward_agent: false,
|
||||
# auth_methods: %w(publickey password)
|
||||
# # password: 'please use keys'
|
||||
# }
|
||||
|
||||
# set :rails_env, :<%= stage %>
|
||||
|
|
|
@ -134,6 +134,51 @@ module Capistrano
|
|||
end
|
||||
end
|
||||
|
||||
describe 'assign ssh_options' do
|
||||
let(:server) { Server.new('user_name@hostname') }
|
||||
|
||||
# before do
|
||||
# server
|
||||
# end
|
||||
|
||||
context 'defaults' do
|
||||
it 'forward agent' do
|
||||
expect(server.netssh_options[:forward_agent]).to eq true
|
||||
end
|
||||
it 'contains user' do
|
||||
expect(server.netssh_options[:user]).to eq 'user_name'
|
||||
end
|
||||
end
|
||||
|
||||
context 'custom' do
|
||||
let(:properties) do
|
||||
{ ssh_options: {
|
||||
user: 'another_user',
|
||||
keys: %w(/home/another_user/.ssh/id_rsa),
|
||||
forward_agent: false,
|
||||
auth_methods: %w(publickey password) } }
|
||||
end
|
||||
|
||||
before do
|
||||
server.with(properties)
|
||||
end
|
||||
|
||||
it 'not forward agent' do
|
||||
expect(server.netssh_options[:forward_agent]).to eq false
|
||||
end
|
||||
it 'contains correct user' do
|
||||
expect(server.netssh_options[:user]).to eq 'another_user'
|
||||
end
|
||||
it 'contains keys' do
|
||||
expect(server.netssh_options[:keys]).to eq %w(/home/another_user/.ssh/id_rsa)
|
||||
end
|
||||
it 'contains auth_methods' do
|
||||
expect(server.netssh_options[:auth_methods]).to eq %w(publickey password)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue