summaryrefslogtreecommitdiff
path: root/lib/chef/chef_fs/knife.rb
diff options
context:
space:
mode:
authorjkeiser <jkeiser@opscode.com>2013-03-12 23:01:02 -0700
committerJohn Keiser <jkeiser@opscode.com>2013-06-07 13:12:28 -0700
commitc60a61d40161c081456cbc298b8133926e22a113 (patch)
tree43f99111ceda07bbb1f07546a63ac3514b3491fe /lib/chef/chef_fs/knife.rb
parent2987fa5d1e965109ddb35fdb950c82622c697e78 (diff)
downloadchef-c60a61d40161c081456cbc298b8133926e22a113.tar.gz
Allow repo_mode and chef_repo_path to be set in knife.rb again
Diffstat (limited to 'lib/chef/chef_fs/knife.rb')
-rw-r--r--lib/chef/chef_fs/knife.rb107
1 files changed, 53 insertions, 54 deletions
diff --git a/lib/chef/chef_fs/knife.rb b/lib/chef/chef_fs/knife.rb
index 26586f174d..04e691b57f 100644
--- a/lib/chef/chef_fs/knife.rb
+++ b/lib/chef/chef_fs/knife.rb
@@ -28,79 +28,78 @@ class Chef
def self.common_options
option :repo_mode,
:long => '--repo-mode MODE',
- :default => "default",
- :description => "Specifies the local repository layout. Values: default or full"
+ :description => "Specifies the local repository layout. Values: default or everything"
option :chef_repo_path,
:long => '--chef-repo-path PATH',
- :default => nil,
- :description => 'Overrides the location of chef repo. Default is specified by chef_repo_paths in the config'
+ :description => 'Overrides the location of chef repo. Default is specified by chef_repo_path in the config'
end
- def chef_fs
- @chef_fs ||= Chef::ChefFS::FileSystem::ChefServerRootDir.new("remote", Chef::Config, config[:repo_mode])
- end
+ def configure_chef
+ super
+ Chef::Config[:repo_mode] = config[:repo_mode] if config[:repo_mode]
- def chef_repo_paths
- @chef_repo_paths ||= begin
- result = config_paths(:chef_repo_path)
- if result
- result
- else
- if Chef::Config[:cookbook_path]
- Array(Chef::Config[:cookbook_path]).flatten.map { |path| File.expand_path('..', path) }
- else
- nil
- end
- end
+ # --chef-repo-path overrides all other paths
+ path_variables = %w(client_path cookbook_path data_bag_path environment_path node_path role_path user_path)
+ if config[:chef_repo_path]
+ Chef::Config[:chef_repo_path] = config[:chef_repo_path]
+ path_variables.each do |variable_name|
+ Chef::Config[variable_name.to_sym] = nil
+ end
+ end
+
+ # Infer chef_repo_path from cookbook_path if not speciifed
+ if !Chef::Config[:chef_repo_path]
+ if Chef::Config[:cookbook_path]
+ Chef::Config[:chef_repo_path] = Array(Chef::Config[:cookbook_path]).flatten.map { |path| File.expand_path('..', path) }
+ end
end
- end
- # Smooth out some inappropriate (for now) variable defaults in Chef.
- def config_paths(name)
- result = case name
- when :data_bag_path
- Chef::Config[name] == Chef::Config.platform_specific_path('/var/chef/data_bags') ? nil : Chef::Config[name]
- when :node_path
- Chef::Config[name] == '/var/chef/node' ? nil : Chef::Config[name]
- when :role_path
- Chef::Config[name] == Chef::Config.platform_specific_path('/var/chef/roles') ? nil : Chef::Config[name]
- else
- Chef::Config[name]
+ # Smooth out some (for now) inappropriate defaults set by Chef
+ if Chef::Config[:data_bag_path] == Chef::Config.platform_specific_path('/var/chef/data_bags')
+ Chef::Config[:data_bag_path] = nil
+ end
+ if Chef::Config[:node_path] == '/var/chef/node'
+ Chef::Config[:node_path] = nil
end
- if result
- Array(result).flatten
- else
- nil
+ if Chef::Config[:role_path] == Chef::Config.platform_specific_path('/var/chef/roles')
+ Chef::Config[:role_path] = nil
end
+
+ # Infer any *_path variables that are not specified
+ if Chef::Config[:chef_repo_path]
+ path_variables.each do |variable_name|
+ chef_repo_paths = Array(Chef::Config[:chef_repo_path]).flatten
+ variable = variable_name.to_sym
+ if !Chef::Config[variable]
+ # cookbook_path -> cookbooks
+ Chef::Config[variable] = chef_repo_paths.map { |path| File.join(path, "#{variable_name[0..-6]}s") }
+ end
+ end
+ end
+ end
+
+ def chef_fs
+ @chef_fs ||= Chef::ChefFS::FileSystem::ChefServerRootDir.new("remote", Chef::Config, Chef::Config[:repo_mode])
end
def object_paths
@object_paths ||= begin
+ if !Chef::Config[:chef_repo_path]
+ Chef::Log.error("Must specify either chef_repo_path or cookbook_path in Chef config file")
+ exit(1)
+ end
+
result = {}
- if config[:repo_mode] == 'everything'
+ if Chef::Config[:repo_mode] == 'everything'
object_names = %w(clients cookbooks data_bags environments nodes roles users)
else
object_names = %w(cookbooks data_bags environments roles)
end
object_names.each do |object_name|
- # If --chef-repo-path is passed in the command line, then override *everything*
- # and assume all the subdirectory is contained in that directory.
- if config[:chef_repo_path]
- paths = [ "#{config[:chef_repo_path]}/#{object_name}" ]
- else
- variable_name = "#{object_name[0..-2]}_path" # cookbooks -> cookbook_path
- paths = config_paths(variable_name.to_sym)
- if !paths
- if !chef_repo_paths
- Chef::Log.error("Must specify either chef_repo_path or #{variable_name} in Chef config file")
- exit(1)
- end
- paths = chef_repo_paths.map { |path| File.join(path, object_name) }
- end
- end
- paths = paths.flatten.map { |path| File.expand_path(path) }
- result[object_name] = paths
+ variable_name = "#{object_name[0..-2]}_path" # cookbooks -> cookbook_path
+ paths = Array(Chef::Config[variable_name]).flatten
+ result[object_name] = paths.map { |path| File.expand_path(path) }
end
result
end
@@ -144,7 +143,7 @@ class Chef
end
# Check chef_repo_path
- chef_repo_paths.each do |chef_repo_path|
+ Array(Chef::Config[:chef_repo_path]).flatten.each do |chef_repo_path|
realest_chef_repo_path = Chef::ChefFS::PathUtils.realest_path(chef_repo_path)
if absolute_path == realest_chef_repo_path
return '/'