diff options
author | Bertrand Paquet <bpaquet@octo.com> | 2013-07-04 22:17:06 +0200 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-10-10 11:29:24 -0700 |
commit | ca716484915abf9a3220d898e458531151130910 (patch) | |
tree | dcee7dafad63bdcd34460070be4302da1954c916 /lib/chef/role.rb | |
parent | 632999b8f25193e01f3851c0012c038164b51751 (diff) | |
download | chef-ca716484915abf9a3220d898e458531151130910.tar.gz |
[CHEF-2928] Allow to use array in role_path
Diffstat (limited to 'lib/chef/role.rb')
-rw-r--r-- | lib/chef/role.rb | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/lib/chef/role.rb b/lib/chef/role.rb index 78bbfadb88..124acdfaf0 100644 --- a/lib/chef/role.rb +++ b/lib/chef/role.rb @@ -233,20 +233,25 @@ class Chef # Load a role from disk - prefers to load the JSON, but will happily load # the raw rb files as well. def self.from_disk(name, force=nil) - js_file = File.join(Chef::Config[:role_path], "#{name}.json") - rb_file = File.join(Chef::Config[:role_path], "#{name}.rb") - - if File.exists?(js_file) || force == "json" - # from_json returns object.class => json_class in the JSON. - Chef::JSONCompat.from_json(IO.read(js_file)) - elsif File.exists?(rb_file) || force == "ruby" - role = Chef::Role.new - role.name(name) - role.from_file(rb_file) - role - else - raise Chef::Exceptions::RoleNotFound, "Role '#{name}' could not be loaded from disk" + paths = Chef::Config[:role_path] + paths = [paths] if paths.is_a? String + + paths.each do |p| + js_file = File.join(p, "#{name}.json") + rb_file = File.join(p, "#{name}.rb") + + if File.exists?(js_file) || force == "json" + # from_json returns object.class => json_class in the JSON. + return Chef::JSONCompat.from_json(IO.read(js_file)) + elsif File.exists?(rb_file) || force == "ruby" + role = Chef::Role.new + role.name(name) + role.from_file(rb_file) + return role + end end + + raise Chef::Exceptions::RoleNotFound, "Role '#{name}' could not be loaded from disk" end end |