From fb246747c22890e851869b66a094b9a1e2c031c8 Mon Sep 17 00:00:00 2001 From: Alex Zepeda Date: Wed, 28 Jan 2015 14:07:23 -0800 Subject: [PATCH 1/3] Set a sensible default value for the options parameter. --- lib/capistrano/dsl/chef.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capistrano/dsl/chef.rb b/lib/capistrano/dsl/chef.rb index 4c1f70c..5f96530 100644 --- a/lib/capistrano/dsl/chef.rb +++ b/lib/capistrano/dsl/chef.rb @@ -1,7 +1,7 @@ module Capistrano module DSL module Chef - def chef_role(name, query = '*:*', options) + def chef_role(name, query = '*:*', options = {}) arg = options.delete(:attribute) || :ipaddress search_proc = case arg From e2c01a74b46f4d7f6c04919b5021b354306d02ec Mon Sep 17 00:00:00 2001 From: Alex Zepeda Date: Wed, 28 Jan 2015 14:07:43 -0800 Subject: [PATCH 2/3] Honor the :limit option. --- lib/capistrano/dsl/chef.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/capistrano/dsl/chef.rb b/lib/capistrano/dsl/chef.rb index 5f96530..264ee2b 100644 --- a/lib/capistrano/dsl/chef.rb +++ b/lib/capistrano/dsl/chef.rb @@ -3,6 +3,7 @@ module DSL module Chef def chef_role(name, query = '*:*', options = {}) arg = options.delete(:attribute) || :ipaddress + limit = options.delete(:limit) search_proc = case arg when Proc @@ -20,6 +21,7 @@ def chef_role(name, query = '*:*', options = {}) end hosts = chef_search(query).map(&search_proc) + hosts = hosts.take(limit) if limit name = [name] unless name.is_a?(Array) From 1356eb85ef3ae98001145b8349a897f7090c37d7 Mon Sep 17 00:00:00 2001 From: Alex Zepeda Date: Wed, 28 Jan 2015 14:07:54 -0800 Subject: [PATCH 3/3] Pass remaining options straight to cap. --- lib/capistrano/dsl/chef.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/capistrano/dsl/chef.rb b/lib/capistrano/dsl/chef.rb index 264ee2b..289b85f 100644 --- a/lib/capistrano/dsl/chef.rb +++ b/lib/capistrano/dsl/chef.rb @@ -27,7 +27,7 @@ def chef_role(name, query = '*:*', options = {}) user = fetch(:user) - name.each { |n| role(name, hosts.map { |h| "#{user ? "#{user}@" : ''}#{h}" }) } + name.each { |n| role(name, hosts.map { |h| "#{user ? "#{user}@" : ''}#{h}" }, options) } end def chef_search(query)