mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Copy the servers yielded to on()
This allows the SSH connection attributes to be temporarily overridden
This commit is contained in:
parent
8125102ae6
commit
837eaca8b1
8 changed files with 52 additions and 4 deletions
|
@ -14,6 +14,15 @@ Reverse Chronological Order:
|
|||
* release_roles did not honour additional property filtering (@townsen)
|
||||
* Refactored and simplified property filtering code (@townsen)
|
||||
|
||||
* Breaking Changes
|
||||
* Hosts with the same name are now consolidated into one irrespective of the
|
||||
user and port. This allows multiple declarations of a server to be made safely.
|
||||
The last declared properties will win. See capistrnorb.com Properties documentation
|
||||
for details.
|
||||
* Inside the on() block the host variable is now a copy of the host, so changes can be
|
||||
made within the block (such as dynamically overriding the user) that will not persist.
|
||||
This is very convenient for switching the SSH user temporarily to 'root' for example.
|
||||
|
||||
* Minor changes
|
||||
* Add role_properties() method (see capistrano.github.io PR for doc) (@townsen)
|
||||
* Add equality syntax ( eg. port: 1234) for property filtering (@townsen)
|
||||
|
|
17
features/sshconnect.feature
Normal file
17
features/sshconnect.feature
Normal file
|
@ -0,0 +1,17 @@
|
|||
Feature: SSH Connection
|
||||
|
||||
Background:
|
||||
Given a test app with the default configuration
|
||||
And servers with the roles app and web
|
||||
And a task which executes as root
|
||||
|
||||
Scenario: Switching from default user to root and back again
|
||||
When I run cap "git:check"
|
||||
Then the task is successful
|
||||
And references in the remote repo are listed
|
||||
When I run cap "am_i_root"
|
||||
Then the task is successful
|
||||
And contains "root" in the output
|
||||
Then I run cap "git:check"
|
||||
Then the task is successful
|
||||
And references in the remote repo are listed
|
|
@ -27,6 +27,10 @@ Given(/^a custom task to generate a file$/) do
|
|||
TestApp.copy_task_to_test_app('spec/support/tasks/database.rake')
|
||||
end
|
||||
|
||||
Given(/^a task which executes as root$/) do
|
||||
TestApp.copy_task_to_test_app('spec/support/tasks/root.rake')
|
||||
end
|
||||
|
||||
Given(/config stage file has line "(.*?)"/) do |line|
|
||||
TestApp.append_to_deploy_file(line)
|
||||
end
|
||||
|
|
|
@ -98,7 +98,7 @@ module Capistrano
|
|||
@properties[key]
|
||||
end
|
||||
|
||||
def respond_to?(method)
|
||||
def respond_to?(method, include_all=false)
|
||||
@properties.has_key?(method)
|
||||
end
|
||||
|
||||
|
|
|
@ -51,8 +51,8 @@ module Capistrano
|
|||
end
|
||||
|
||||
def on(hosts, options={}, &block)
|
||||
subset = Configuration.env.filter hosts
|
||||
SSHKit::Coordinator.new(subset).each(options, &block)
|
||||
subset_copy = Marshal.dump(Configuration.env.filter(hosts))
|
||||
SSHKit::Coordinator.new(Marshal.load(subset_copy)).each(options, &block)
|
||||
end
|
||||
|
||||
def run_locally(&block)
|
||||
|
|
11
spec/support/Vagrantfile
vendored
11
spec/support/Vagrantfile
vendored
|
@ -1,3 +1,5 @@
|
|||
require 'open-uri'
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
|
||||
config.ssh.insert_key = false
|
||||
|
@ -8,6 +10,15 @@ Vagrant.configure("2") do |config|
|
|||
config.vm.box = 'hashicorp/precise64'
|
||||
config.vm.network "forwarded_port", guest: 22, host: "222#{i}".to_i
|
||||
config.vm.provision :shell, inline: 'sudo apt-get -y install git-core'
|
||||
|
||||
vagrantkey = open("https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub", "r",&:read)
|
||||
|
||||
config.vm.provision :shell,
|
||||
inline: <<-INLINE
|
||||
install -d -m 700 /root/.ssh
|
||||
echo -e "#{vagrantkey}" > /root/.ssh/authorized_keys
|
||||
chmod 0600 /root/.ssh/authorized_keys
|
||||
INLINE
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
7
spec/support/tasks/root.rake
Normal file
7
spec/support/tasks/root.rake
Normal file
|
@ -0,0 +1,7 @@
|
|||
task :am_i_root do
|
||||
on roles(:all) do |host|
|
||||
host.user = 'root'
|
||||
ident = capture :id, '-a'
|
||||
info "I am #{ident}"
|
||||
end
|
||||
end
|
|
@ -13,7 +13,7 @@ module TestApp
|
|||
set :deploy_to, '#{deploy_to}'
|
||||
set :repo_url, 'git://github.com/capistrano/capistrano.git'
|
||||
set :branch, 'master'
|
||||
set :ssh_options, { keys: "\#{ENV['HOME']}/.vagrant.d/insecure_private_key" }
|
||||
set :ssh_options, { keys: "\#{ENV['HOME']}/.vagrant.d/insecure_private_key", auth_methods: ['publickey'] }
|
||||
server 'vagrant@localhost:2220', roles: %w{web app}
|
||||
set :linked_files, #{linked_files}
|
||||
set :linked_dirs, #{linked_dirs}
|
||||
|
|
Loading…
Reference in a new issue