diff options
author | Vasiliy Tolstov <v.tolstov@selfip.ru> | 2014-11-16 23:51:52 +0300 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-01-25 13:31:52 -0800 |
commit | f68f34981b3549ae065176f40035cb9ecd59f594 (patch) | |
tree | d2b8852babcb437d47dc9efa1c851adf9260e85b /lib/chef/application | |
parent | f923755a505c31745f6df14e201149128ba4ebec (diff) | |
download | chef-f68f34981b3549ae065176f40035cb9ecd59f594.tar.gz |
add ability to fetch recipes like in chef-solo when using local-mode
Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
Diffstat (limited to 'lib/chef/application')
-rw-r--r-- | lib/chef/application/client.rb | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index 403b5c0593..30799e9c19 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -205,6 +205,10 @@ class Chef::Application::Client < Chef::Application :description => "Fork client", :boolean => true + option :recipe_url, + :long => "--recipe-url", + :description => "Pull down a remote gzipped tarball of recipes and untar it to the cookbook cache. Only useful in local mode (-z/--local-mode)" + option :enable_reporting, :short => "-R", :long => "--enable-reporting", @@ -258,7 +262,7 @@ class Chef::Application::Client < Chef::Application super raise Chef::Exceptions::PIDFileLockfileMatch if Chef::Util::PathHelper.paths_eql? (Chef::Config[:pid_file] || '' ), (Chef::Config[:lockfile] || '') - + Chef::Config[:specific_recipes] = cli_arguments.map { |file| File.expand_path(file) } Chef::Config[:chef_server_url] = config[:chef_server_url] if config.has_key? :chef_server_url @@ -266,6 +270,17 @@ class Chef::Application::Client < Chef::Application Chef::Config.local_mode = config[:local_mode] if config.has_key?(:local_mode) if Chef::Config.local_mode && !Chef::Config.has_key?(:cookbook_path) && !Chef::Config.has_key?(:chef_repo_path) Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd) + elsif Chef::Config.local_mode && Chef::Config.has_key?(:recipe_url) && Chef::Config.has_key?(:cookbook_path) + cookbooks_path = Array(Chef::Config[:cookbook_path]).detect{|e| e =~ /\/cookbooks\/*$/ } + recipes_path = File.expand_path(File.join(cookbooks_path, '..')) + + Chef::Log.debug "Cleanup path #{recipes_path} before extract recipes into it" + FileUtils.rm_rf(recipes_path, :secure => true) + Chef::Log.debug "Creating path #{recipes_path} to extract recipes into" + FileUtils.mkdir_p(recipes_path) + tarball_path = File.join(recipes_path, 'recipes.tgz') + fetch_recipe_tarball(Chef::Config[:recipe_url], tarball_path) + Chef::Mixin::Command.run_command(:command => "tar zxvf #{tarball_path} -C #{recipes_path}") end Chef::Config.chef_zero.host = config[:chef_zero_host] if config[:chef_zero_host] Chef::Config.chef_zero.port = config[:chef_zero_port] if config[:chef_zero_port] @@ -442,4 +457,13 @@ class Chef::Application::Client < Chef::Application msg += audit_mode_settings_explaination return msg end + + def fetch_recipe_tarball(url, path) + Chef::Log.debug("Download recipes tarball from #{url} to #{path}") + File.open(path, 'wb') do |f| + open(url) do |r| + f.write(r.read) + end + end + end end |