summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-02-10 11:48:51 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2016-02-10 11:48:51 -0800
commitfcc18aa5062932ca52498328d410910d64bb0eb9 (patch)
tree1fbd1e1c7ad72895c8d413a71509b3b048dc1a16 /lib/chef
parent09d1cbfb091094c6d5e0d9b5c715c1555ac21f83 (diff)
downloadchef-fcc18aa5062932ca52498328d410910d64bb0eb9.tar.gz
remove rm -rf in chef solo recipe_url
- deprecates '-r' used for the recipe_url in chef-solo - adds --delete-entire-chef-repo option for users who want the old behavior back. - cleans up some old code closes #3802 closes #1515 closes #1751
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/application/client.rb30
-rw-r--r--lib/chef/application/solo.rb27
2 files changed, 40 insertions, 17 deletions
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb
index 1f232c651d..1a7d8d046d 100644
--- a/lib/chef/application/client.rb
+++ b/lib/chef/application/client.rb
@@ -25,6 +25,7 @@ require "chef/log"
require "chef/config_fetcher"
require "chef/handler/error_report"
require "chef/workstation_config_loader"
+require "chef/mixin/shell_out"
class Chef::Application::Client < Chef::Application
include Chef::Mixin::ShellOut
@@ -279,6 +280,11 @@ class Chef::Application::Client < Chef::Application
:description => "Enable fips mode",
:boolean => true
+ option :delete_entire_chef_repo,
+ :long => "--delete-entire-chef-repo",
+ :description => "DANGEROUS: does what it says, only useful with --recipe-url",
+ :boolean => true
+
IMMEDIATE_RUN_SIGNAL = "1".freeze
attr_reader :chef_client_json
@@ -307,15 +313,21 @@ class Chef::Application::Client < Chef::Application
Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Dir.pwd)
end
- if !Chef::Config.local_mode && Chef::Config.has_key?(:recipe_url)
- Chef::Application.fatal!("chef-client recipe-url can be used only in local-mode", 1)
- elsif Chef::Config.local_mode && Chef::Config.has_key?(:recipe_url)
- Chef::Log.debug "Creating path #{Chef::Config.chef_repo_path} to extract recipes into"
- FileUtils.mkdir_p(Chef::Config.chef_repo_path)
- tarball_path = File.join(Chef::Config.chef_repo_path, "recipes.tgz")
- fetch_recipe_tarball(Chef::Config[:recipe_url], tarball_path)
- result = shell_out!("tar zxvf #{tarball_path} -C #{Chef::Config.chef_repo_path}")
- Chef::Log.debug "#{result.stdout}"
+ if Chef::Config[:recipe_url]
+ if !Chef::Config.local_mode
+ Chef::Application.fatal!("chef-client recipe-url can be used only in local-mode", 1)
+ else
+ if Chef::Config[:delete_entire_chef_repo]
+ Chef::Log.debug "Cleanup path #{Chef::Config.chef_repo_path} before extract recipes into it"
+ FileUtils.rm_rf(recipes_path, :secure => true)
+ end
+ Chef::Log.debug "Creating path #{Chef::Config.chef_repo_path} to extract recipes into"
+ FileUtils.mkdir_p(Chef::Config.chef_repo_path)
+ tarball_path = File.join(Chef::Config.chef_repo_path, "recipes.tgz")
+ fetch_recipe_tarball(Chef::Config[:recipe_url], tarball_path)
+ result = shell_out!("tar zxvf #{tarball_path} -C #{Chef::Config.chef_repo_path}")
+ Chef::Log.debug "#{result.stdout}"
+ end
end
Chef::Config.chef_zero.host = config[:chef_zero_host] if config[:chef_zero_host]
diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb
index 26bd6ba52e..c5d7549ffe 100644
--- a/lib/chef/application/solo.rb
+++ b/lib/chef/application/solo.rb
@@ -25,8 +25,10 @@ require "chef/log"
require "chef/rest"
require "chef/config_fetcher"
require "fileutils"
+require "chef/mixin/shell_out"
class Chef::Application::Solo < Chef::Application
+ include Chef::Mixin::ShellOut
option :config_file,
:short => "-c CONFIG",
@@ -135,10 +137,9 @@ class Chef::Application::Solo < Chef::Application
:proc => lambda { |s| s.to_i }
option :recipe_url,
- :short => "-r RECIPE_URL",
- :long => "--recipe-url RECIPE_URL",
- :description => "Pull down a remote gzipped tarball of recipes and untar it to the cookbook cache.",
- :proc => nil
+ :short => "-r RECIPE_URL",
+ :long => "--recipe-url RECIPE_URL",
+ :description => "Pull down a remote gzipped tarball of recipes and untar it to the cookbook cache."
option :version,
:short => "-v",
@@ -191,6 +192,11 @@ class Chef::Application::Solo < Chef::Application
:description => "Only run the bare minimum ohai plugins chef needs to function",
:boolean => true
+ option :delete_entire_chef_repo,
+ :long => "--delete-entire-chef-repo",
+ :description => "DANGEROUS: does what it says, only useful with --recipe-url",
+ :boolean => true
+
attr_reader :chef_client_json
def initialize
@@ -210,17 +216,22 @@ class Chef::Application::Solo < Chef::Application
Chef::Application.fatal!(unforked_interval_error_message) if !Chef::Config[:client_fork] && Chef::Config[:interval]
+ Chef::Log.deprecation("-r MUST be changed to --recipe-url, the -r option will be changed in Chef 13.0") if ARGV.include?("-r")
+
if Chef::Config[:recipe_url]
- cookbooks_path = Array(Chef::Config[:cookbook_path]).detect { |e| e =~ /\/cookbooks\/*$/ }
+ cookbooks_path = Array(Chef::Config[:cookbook_path]).detect{|e| e =~ /#{Chef::Config.platform_path_separator_escaped}cookbooks#{Chef::Config.platform_path_separator_escaped}*$/ }
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)
+ if Chef::Config[:delete_entire_chef_repo]
+ Chef::Log.debug "Cleanup path #{recipes_path} before extract recipes into it"
+ FileUtils.rm_rf(recipes_path, :secure => true)
+ end
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)
- Mixlib::ShellOut.new("tar zxvf #{tarball_path} -C #{recipes_path}").run_command
+ result = shell_out!("tar zxvf #{tarball_path} -C #{recipes_path}")
+ Chef::Log.debug "#{result.stdout}"
end
# json_attribs shuld be fetched after recipe_url tarball is unpacked.