diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e8df3c4..7090179c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/features/sshconnect.feature b/features/sshconnect.feature new file mode 100644 index 00000000..addc1c5c --- /dev/null +++ b/features/sshconnect.feature @@ -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 diff --git a/features/step_definitions/setup.rb b/features/step_definitions/setup.rb index b7c72f39..8fc1e1c8 100644 --- a/features/step_definitions/setup.rb +++ b/features/step_definitions/setup.rb @@ -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 diff --git a/lib/capistrano/configuration/server.rb b/lib/capistrano/configuration/server.rb index 6d3cbd67..35c55d34 100644 --- a/lib/capistrano/configuration/server.rb +++ b/lib/capistrano/configuration/server.rb @@ -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 diff --git a/lib/capistrano/dsl.rb b/lib/capistrano/dsl.rb index b93199f4..431967e3 100644 --- a/lib/capistrano/dsl.rb +++ b/lib/capistrano/dsl.rb @@ -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) diff --git a/spec/support/Vagrantfile b/spec/support/Vagrantfile index f29e253d..7ef80db9 100644 --- a/spec/support/Vagrantfile +++ b/spec/support/Vagrantfile @@ -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 diff --git a/spec/support/tasks/root.rake b/spec/support/tasks/root.rake new file mode 100644 index 00000000..82e31143 --- /dev/null +++ b/spec/support/tasks/root.rake @@ -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 diff --git a/spec/support/test_app.rb b/spec/support/test_app.rb index 36d007ad..c5d9eaac 100644 --- a/spec/support/test_app.rb +++ b/spec/support/test_app.rb @@ -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}