diff options
Diffstat (limited to 'lib/chef/role.rb')
-rw-r--r-- | lib/chef/role.rb | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/chef/role.rb b/lib/chef/role.rb index 78bbfadb88..6ad58b816d 100644 --- a/lib/chef/role.rb +++ b/lib/chef/role.rb @@ -233,20 +233,24 @@ 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 = Array(Chef::Config[:role_path]) + + 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 |