Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/capistrano/dsl/chef.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Capistrano
module DSL
module Chef
def chef_role(name, query = '*:*', options)
def chef_role(name, query = '*:*', options = {})
arg = options.delete(:attribute) || :ipaddress
limit = options.delete(:limit)

search_proc = case arg
when Proc
Expand All @@ -20,12 +21,13 @@ 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)

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)
Expand Down