diff options
author | danielsdeleo <dan@opscode.com> | 2013-01-17 13:43:28 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-01-17 15:02:54 -0800 |
commit | 62f9b0e3be8e22eef092163c331b7d3f8d350f94 (patch) | |
tree | 6b37c7a275918580b59c16de32a16c24f5dbe77f /lib/chef | |
parent | 30ec971df95264b39e5e403c08b634d4708f5bee (diff) | |
parent | b568c4d060765e75023f50f24d0a394ada5aed0b (diff) | |
download | chef-62f9b0e3be8e22eef092163c331b7d3f8d350f94.tar.gz |
Merge branch '10-stable' into integrate-chef-10-18-0
Conflicts:
.gitattributes
chef-expander/Rakefile
chef-expander/lib/chef/expander/version.rb
chef-server-api/Rakefile
chef-server-api/chef-server-api.gemspec
chef-server-api/lib/chef-server-api/version.rb
chef-server-webui/Rakefile
chef-server-webui/chef-server-webui.gemspec
chef-server-webui/lib/chef-server-webui/version.rb
chef-server/Rakefile
chef-server/lib/chef-server/version.rb
chef-solr/lib/chef/solr/version.rb
chef.gemspec
chef/Rakefile
chef/spec/support/platform_helpers.rb
chef/spec/support/shared/functional/file_resource.rb
chef/spec/unit/api_client_spec.rb
chef/spec/unit/provider/directory_spec.rb
ci/jenkins_run_tests.bat
ci/jenkins_run_tests.sh
distro/common/html/chef-client.8.html
distro/common/html/chef-expander.8.html
distro/common/html/chef-expanderctl.8.html
distro/common/html/chef-server-webui.8.html
distro/common/html/chef-server.8.html
distro/common/html/chef-shell.1.html
distro/common/html/chef-solo.8.html
distro/common/html/chef-solr.8.html
distro/common/html/knife-bootstrap.1.html
distro/common/html/knife-client.1.html
distro/common/html/knife-configure.1.html
distro/common/html/knife-cookbook-site.1.html
distro/common/html/knife-cookbook.1.html
distro/common/html/knife-data-bag.1.html
distro/common/html/knife-environment.1.html
distro/common/html/knife-exec.1.html
distro/common/html/knife-index.1.html
distro/common/html/knife-node.1.html
distro/common/html/knife-role.1.html
distro/common/html/knife-search.1.html
distro/common/html/knife-ssh.1.html
distro/common/html/knife-status.1.html
distro/common/html/knife-tag.1.html
distro/common/html/knife.1.html
distro/common/man/man1/chef-shell.1
distro/common/man/man1/knife-bootstrap.1
distro/common/man/man1/knife-client.1
distro/common/man/man1/knife-configure.1
distro/common/man/man1/knife-cookbook-site.1
distro/common/man/man1/knife-cookbook.1
distro/common/man/man1/knife-data-bag.1
distro/common/man/man1/knife-environment.1
distro/common/man/man1/knife-exec.1
distro/common/man/man1/knife-index.1
distro/common/man/man1/knife-node.1
distro/common/man/man1/knife-role.1
distro/common/man/man1/knife-search.1
distro/common/man/man1/knife-ssh.1
distro/common/man/man1/knife-status.1
distro/common/man/man1/knife-tag.1
distro/common/man/man1/knife.1
distro/common/man/man8/chef-client.8
distro/common/man/man8/chef-expander.8
distro/common/man/man8/chef-expanderctl.8
distro/common/man/man8/chef-server-webui.8
distro/common/man/man8/chef-server.8
distro/common/man/man8/chef-solo.8
distro/common/man/man8/chef-solr.8
lib/chef/api_client.rb
lib/chef/rest.rb
lib/chef/version.rb
spec/functional/knife/ssh_spec.rb
spec/functional/resource/cookbook_file_spec.rb
spec/spec_helper.rb
spec/stress/win32/security_spec.rb
spec/support/shared/functional/securable_resource.rb
spec/unit/config_spec.rb
spec/unit/knife/ssh_spec.rb
Diffstat (limited to 'lib/chef')
25 files changed, 349 insertions, 203 deletions
diff --git a/lib/chef/api_client.rb b/lib/chef/api_client.rb index 32e1eee017..4fdac03754 100644 --- a/lib/chef/api_client.rb +++ b/lib/chef/api_client.rb @@ -127,6 +127,11 @@ class Chef api_client.reregister end + def self.reregister(name) + api_client = load(name) + api_client.reregister + end + def self.list(inflate=false) if inflate response = Hash.new diff --git a/lib/chef/config.rb b/lib/chef/config.rb index d05692ddc8..83b8a86819 100644 --- a/lib/chef/config.rb +++ b/lib/chef/config.rb @@ -72,7 +72,7 @@ class Chef # url<String>:: String to be set for all of the chef-server-api URL's # config_attr_writer :chef_server_url do |url| - url.strip! + url = url.strip configure do |c| [ :registration_url, :template_url, diff --git a/lib/chef/cookbook/chefignore.rb b/lib/chef/cookbook/chefignore.rb index e9d54639e4..af145f3a3c 100644 --- a/lib/chef/cookbook/chefignore.rb +++ b/lib/chef/cookbook/chefignore.rb @@ -20,7 +20,7 @@ class Chef class Cookbook class Chefignore - COMMENTS_AND_WHITESPACE = /^\w*(?:#.*)?$/ + COMMENTS_AND_WHITESPACE = /^\s*(?:#.*)?$/ attr_reader :ignores diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index 48de17cc5a..e98da77d7f 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -104,9 +104,7 @@ class Chef end def empty? - cookbook_settings.inject(true) do |all_empty, files| - all_empty && files.last.empty? - end + @cookbook_settings.values.all? { |files_hash| files_hash.empty? } end def merge!(other_cookbook_loader) diff --git a/lib/chef/dsl/recipe.rb b/lib/chef/dsl/recipe.rb index 1bfe8da0e0..88006aced3 100644 --- a/lib/chef/dsl/recipe.rb +++ b/lib/chef/dsl/recipe.rb @@ -61,11 +61,11 @@ class Chef # If we have a resource like this one, we want to steal its state args << run_context resource = resource_class.new(*args) + resource.source_line = caller[0] resource.load_prior_resource resource.cookbook_name = cookbook_name resource.recipe_name = @recipe_name resource.params = @params - resource.source_line = caller[0] # Determine whether this resource is being created in the context of an enclosing Provider resource.enclosing_provider = self.is_a?(Chef::Provider) ? self : nil # Evaluate resource attribute DSL diff --git a/lib/chef/formatters/doc.rb b/lib/chef/formatters/doc.rb index e5b2ab17d7..6a969404c1 100644 --- a/lib/chef/formatters/doc.rb +++ b/lib/chef/formatters/doc.rb @@ -21,7 +21,7 @@ class Chef end def run_completed(node) - if Chef::Config[:whyrun] + if Chef::Config[:why_run] puts "Chef Client finished, #{@updated_resources} resources would have been updated" else puts "Chef Client finished, #{@updated_resources} resources updated" @@ -29,7 +29,7 @@ class Chef end def run_failed(exception) - if Chef::Config[:whyrun] + if Chef::Config[:why_run] puts "Chef Client failed. #{@updated_resources} resources would have been updated" else puts "Chef Client failed. #{@updated_resources} resources updated" diff --git a/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb b/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb index 57d8de0ef9..813f755560 100644 --- a/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +++ b/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb @@ -56,6 +56,7 @@ class Chef return nil if dynamic_resource? @snippet ||= begin if file = resource.source_line[/^(([\w]:)?[^:]+):([\d]+)/,1] and line = resource.source_line[/^#{file}:([\d]+)/,1].to_i + return nil unless ::File.exists?(file) lines = IO.readlines(file) relevant_lines = ["# In #{file}\n\n"] diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index a4c117e28f..53b31ad676 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -200,13 +200,13 @@ class Chef ssh = Chef::Knife::Ssh.new ssh.ui = ui ssh.name_args = [ server_name, ssh_command ] - ssh.config[:ssh_user] = config[:ssh_user] + ssh.config[:ssh_user] = Chef::Config[:knife][:ssh_user] || config[:ssh_user] ssh.config[:ssh_password] = config[:ssh_password] ssh.config[:ssh_port] = Chef::Config[:knife][:ssh_port] || config[:ssh_port] ssh.config[:ssh_gateway] = Chef::Config[:knife][:ssh_gateway] || config[:ssh_gateway] - ssh.config[:identity_file] = config[:identity_file] + ssh.config[:identity_file] = Chef::Config[:knife][:identity_file] || config[:identity_file] ssh.config[:manual] = true - ssh.config[:host_key_verify] = config[:host_key_verify] + ssh.config[:host_key_verify] = Chef::Config[:knife][:host_key_verify] || config[:host_key_verify] ssh.config[:on_error] = :raise ssh end diff --git a/lib/chef/knife/bootstrap/archlinux-gems.erb b/lib/chef/knife/bootstrap/archlinux-gems.erb index 85d6236197..4b9cd07c8f 100644 --- a/lib/chef/knife/bootstrap/archlinux-gems.erb +++ b/lib/chef/knife/bootstrap/archlinux-gems.erb @@ -10,23 +10,16 @@ if [ ! -f /usr/bin/chef-client ]; then fi mkdir -p /etc/chef -( -cat <<'EOP' + +awk NF > /etc/chef/validation.pem <<'EOP' <%= validation_key %> EOP -) > /tmp/validation.pem -awk NF /tmp/validation.pem > /etc/chef/validation.pem -rm /tmp/validation.pem chmod 0600 /etc/chef/validation.pem <% if @chef_config[:encrypted_data_bag_secret] -%> -( -cat <<'EOP' +awk NF > /etc/chef/encrypted_data_bag_secret <<'EOP' <%= encrypted_data_bag_secret %> EOP -) > /tmp/encrypted_data_bag_secret -awk NF /tmp/encrypted_data_bag_secret > /etc/chef/encrypted_data_bag_secret -rm /tmp/encrypted_data_bag_secret chmod 0600 /etc/chef/encrypted_data_bag_secret <% end -%> @@ -35,16 +28,13 @@ chmod 0600 /etc/chef/encrypted_data_bag_secret mkdir -p /etc/chef/ohai/hints <% @chef_config[:knife][:hints].each do |name, hash| -%> -( -cat <<'EOP' +cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' <%= hash.to_json %> EOP -) > /etc/chef/ohai/hints/<%= name %>.json <% end -%> <% end -%> -( -cat <<'EOP' +cat > /etc/chef/client.rb <<'EOP' log_level :info log_location STDOUT chef_server_url "<%= @chef_config[:chef_server_url] %>" @@ -64,12 +54,9 @@ http_proxy "<%= knife_config[:bootstrap_proxy] %>" https_proxy "<%= knife_config[:bootstrap_proxy] %>" <% end -%> EOP -) > /etc/chef/client.rb -( -cat <<'EOP' +cat > /etc/chef/first-boot.json <<'EOP' <%= first_boot.to_json %> EOP -) > /etc/chef/first-boot.json <%= start_chef %>' diff --git a/lib/chef/knife/bootstrap/centos5-gems.erb b/lib/chef/knife/bootstrap/centos5-gems.erb index f9626c3c2b..5db3c1a0e8 100644 --- a/lib/chef/knife/bootstrap/centos5-gems.erb +++ b/lib/chef/knife/bootstrap/centos5-gems.erb @@ -2,6 +2,11 @@ bash -c ' <%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%> if [ ! -f /usr/bin/chef-client ]; then + tmp_dir=$(mktemp -d) || exit 1 + pushd "$tmp_dir" + + yum install -y wget + wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm rpm -Uvh epel-release-5-4.noarch.rpm wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://rpm.aegisco.com/aegisco/rhel/aegisco-rhel.rpm @@ -9,11 +14,11 @@ if [ ! -f /usr/bin/chef-client ]; then yum install -y ruby ruby-devel gcc gcc-c++ automake autoconf make - cd /tmp - wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://production.cf.rubygems.org/rubygems/rubygems-1.6.2.tgz - tar zxf rubygems-1.6.2.tgz - cd rubygems-1.6.2 - ruby setup.rb --no-format-executable + wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://production.cf.rubygems.org/rubygems/rubygems-1.6.2.tgz -O - | tar zxf - + (cd rubygems-1.6.2 && ruby setup.rb --no-format-executable) + + popd + rm -r "$tmp_dir" fi gem update --system @@ -23,23 +28,15 @@ gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %> mkdir -p /etc/chef -( -cat <<'EOP' +awk NF > /etc/chef/validation.pem <<'EOP' <%= validation_key %> EOP -) > /tmp/validation.pem -awk NF /tmp/validation.pem > /etc/chef/validation.pem -rm /tmp/validation.pem chmod 0600 /etc/chef/validation.pem <% if @chef_config[:encrypted_data_bag_secret] -%> -( -cat <<'EOP' +awk NF > /etc/chef/encrypted_data_bag_secret <<'EOP' <%= encrypted_data_bag_secret %> EOP -) > /tmp/encrypted_data_bag_secret -awk NF /tmp/encrypted_data_bag_secret > /etc/chef/encrypted_data_bag_secret -rm /tmp/encrypted_data_bag_secret chmod 0600 /etc/chef/encrypted_data_bag_secret <% end -%> @@ -48,24 +45,18 @@ chmod 0600 /etc/chef/encrypted_data_bag_secret mkdir -p /etc/chef/ohai/hints <% @chef_config[:knife][:hints].each do |name, hash| -%> -( -cat <<'EOP' +cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' <%= hash.to_json %> EOP -) > /etc/chef/ohai/hints/<%= name %>.json <% end -%> <% end -%> -( -cat <<'EOP' +cat > /etc/chef/client.rb <<'EOP' <%= config_content %> EOP -) > /etc/chef/client.rb -( -cat <<'EOP' +cat > /etc/chef/first-boot.json <<'EOP' <%= first_boot.to_json %> EOP -) > /etc/chef/first-boot.json <%= start_chef %>' diff --git a/lib/chef/knife/bootstrap/chef-full.erb b/lib/chef/knife/bootstrap/chef-full.erb index 771ef85884..b7d73b3442 100644 --- a/lib/chef/knife/bootstrap/chef-full.erb +++ b/lib/chef/knife/bootstrap/chef-full.erb @@ -16,32 +16,25 @@ version_string="-v <%= chef_version %>" if ! exists /usr/bin/chef-client; then if exists wget; then bash <(wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %> ${install_sh} -O -) ${version_string} + elif exists curl; then + bash <(curl -L <%= "--proxy \"#{knife_config[:bootstrap_proxy]}\" " if knife_config[:bootstrap_proxy] %> ${install_sh}) ${version_string} else - if exists curl; then - bash <(curl -L <%= "--proxy=on " if knife_config[:bootstrap_proxy] %> ${install_sh}) ${version_string} - fi + echo "Neither wget nor curl found. Please install one and try again." >&2 + exit 1 fi fi mkdir -p /etc/chef -( -cat <<'EOP' +awk NF > /etc/chef/validation.pem <<'EOP' <%= validation_key %> EOP -) > /tmp/validation.pem -awk NF /tmp/validation.pem > /etc/chef/validation.pem -rm /tmp/validation.pem chmod 0600 /etc/chef/validation.pem <% if @chef_config[:encrypted_data_bag_secret] -%> -( -cat <<'EOP' +awk NF > /etc/chef/encrypted_data_bag_secret <<'EOP' <%= encrypted_data_bag_secret %> EOP -) > /tmp/encrypted_data_bag_secret -awk NF /tmp/encrypted_data_bag_secret > /etc/chef/encrypted_data_bag_secret -rm /tmp/encrypted_data_bag_secret chmod 0600 /etc/chef/encrypted_data_bag_secret <% end -%> @@ -50,24 +43,18 @@ chmod 0600 /etc/chef/encrypted_data_bag_secret mkdir -p /etc/chef/ohai/hints <% @chef_config[:knife][:hints].each do |name, hash| -%> -( -cat <<'EOP' +cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' <%= hash.to_json %> EOP -) > /etc/chef/ohai/hints/<%= name %>.json <% end -%> <% end -%> -( -cat <<'EOP' +cat > /etc/chef/client.rb <<'EOP' <%= config_content %> EOP -) > /etc/chef/client.rb -( -cat <<'EOP' +cat > /etc/chef/first-boot.json <<'EOP' <%= first_boot.to_json %> EOP -) > /etc/chef/first-boot.json <%= start_chef %>' diff --git a/lib/chef/knife/bootstrap/fedora13-gems.erb b/lib/chef/knife/bootstrap/fedora13-gems.erb index a8448342df..e555c0652a 100644 --- a/lib/chef/knife/bootstrap/fedora13-gems.erb +++ b/lib/chef/knife/bootstrap/fedora13-gems.erb @@ -10,23 +10,15 @@ gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %> mkdir -p /etc/chef -( -cat <<'EOP' +awk NF > /etc/chef/validation.pem <<'EOP' <%= validation_key %> EOP -) > /tmp/validation.pem -awk NF /tmp/validation.pem > /etc/chef/validation.pem -rm /tmp/validation.pem chmod 0600 /etc/chef/validation.pem <% if @chef_config[:encrypted_data_bag_secret] -%> -( -cat <<'EOP' +awk NF > /etc/chef/encrypted_data_bag_secret <<'EOP' <%= encrypted_data_bag_secret %> EOP -) > /tmp/encrypted_data_bag_secret -awk NF /tmp/encrypted_data_bag_secret > /etc/chef/encrypted_data_bag_secret -rm /tmp/encrypted_data_bag_secret chmod 0600 /etc/chef/encrypted_data_bag_secret <% end -%> @@ -35,24 +27,18 @@ chmod 0600 /etc/chef/encrypted_data_bag_secret mkdir -p /etc/chef/ohai/hints <% @chef_config[:knife][:hints].each do |name, hash| -%> -( -cat <<'EOP' +cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' <%= hash.to_json %> EOP -) > /etc/chef/ohai/hints/<%= name %>.json <% end -%> <% end -%> -( -cat <<'EOP' +cat > /etc/chef/client.rb <<'EOP' <%= config_content %> EOP -) > /etc/chef/client.rb -( -cat <<'EOP' +cat > /etc/chef/first-boot.json <<'EOP' <%= first_boot.to_json %> EOP -) > /etc/chef/first-boot.json <%= start_chef %>' diff --git a/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb b/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb index 0e44361d82..93ec208ac3 100644 --- a/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +++ b/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb @@ -10,23 +10,15 @@ fi apt-get update apt-get install -y chef -( -cat <<'EOP' +awk NF > /etc/chef/validation.pem <<'EOP' <%= validation_key %> EOP -) > /tmp/validation.pem -awk NF /tmp/validation.pem > /etc/chef/validation.pem -rm /tmp/validation.pem chmod 0600 /etc/chef/validation.pem <% if @chef_config[:encrypted_data_bag_secret] -%> -( -cat <<'EOP' +awk NF > /etc/chef/encrypted_data_bag_secret <<'EOP' <%= encrypted_data_bag_secret %> EOP -) > /tmp/encrypted_data_bag_secret -awk NF /tmp/encrypted_data_bag_secret > /etc/chef/encrypted_data_bag_secret -rm /tmp/encrypted_data_bag_secret chmod 0600 /etc/chef/encrypted_data_bag_secret <% end -%> @@ -35,11 +27,9 @@ chmod 0600 /etc/chef/encrypted_data_bag_secret mkdir -p /etc/chef/ohai/hints <% @chef_config[:knife][:hints].each do |name, hash| -%> -( -cat <<'EOP' +cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' <%= hash.to_json %> EOP -) > /etc/chef/ohai/hints/<%= name %>.json <% end -%> <% end -%> @@ -56,10 +46,8 @@ echo 'http_proxy "knife_config[:bootstrap_proxy]"' >> /etc/chef/client.rb echo 'https_proxy "knife_config[:bootstrap_proxy]"' >> /etc/chef/client.rb <% end -%> -( -cat <<'EOP' +cat > /etc/chef/first-boot.json <<'EOP' <%= first_boot.to_json %> EOP -) > /etc/chef/first-boot.json <%= start_chef %>' diff --git a/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb b/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb index 63448fc4d3..f5ecc5f7b9 100644 --- a/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +++ b/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb @@ -4,11 +4,8 @@ bash -c ' if [ ! -f /usr/bin/chef-client ]; then apt-get update apt-get install -y ruby ruby1.8-dev build-essential wget libruby-extras libruby1.8-extras - cd /tmp - wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://production.cf.rubygems.org/rubygems/rubygems-1.6.2.tgz - tar zxf rubygems-1.6.2.tgz - cd rubygems-1.6.2 - ruby setup.rb --no-format-executable + wget <%= "--proxy=on " if knife_config[:bootstrap_proxy] %>http://production.cf.rubygems.org/rubygems/rubygems-1.6.2.tgz -O - | tar zxf - + (cd rubygems-1.6.2 && ruby setup.rb --no-format-executable) fi gem update --no-rdoc --no-ri @@ -17,23 +14,15 @@ gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %> mkdir -p /etc/chef -( -cat <<'EOP' +awk NF > /etc/chef/validation.pem <<'EOP' <%= validation_key %> EOP -) > /tmp/validation.pem -awk NF /tmp/validation.pem > /etc/chef/validation.pem -rm /tmp/validation.pem chmod 0600 /etc/chef/validation.pem <% if @chef_config[:encrypted_data_bag_secret] -%> -( -cat <<'EOP' +awk NF > /etc/chef/encrypted_data_bag_secret <<'EOP' <%= encrypted_data_bag_secret %> EOP -) > /tmp/encrypted_data_bag_secret -awk NF /tmp/encrypted_data_bag_secret > /etc/chef/encrypted_data_bag_secret -rm /tmp/encrypted_data_bag_secret chmod 0600 /etc/chef/encrypted_data_bag_secret <% end -%> @@ -42,24 +31,18 @@ chmod 0600 /etc/chef/encrypted_data_bag_secret mkdir -p /etc/chef/ohai/hints <% @chef_config[:knife][:hints].each do |name, hash| -%> -( -cat <<'EOP' +cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' <%= hash.to_json %> EOP -) > /etc/chef/ohai/hints/<%= name %>.json <% end -%> <% end -%> -( -cat <<'EOP' +cat > /etc/chef/client.rb <<'EOP' <%= config_content %> EOP -) > /etc/chef/client.rb -( -cat <<'EOP' +cat > /etc/chef/first-boot.json <<'EOP' <%= first_boot.to_json %> EOP -) > /etc/chef/first-boot.json <%= start_chef %>' diff --git a/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb b/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb index e7da7db39b..7d9549a125 100644 --- a/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +++ b/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb @@ -12,23 +12,15 @@ gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %> mkdir -p /etc/chef -( -cat <<'EOP' +awk NF > /etc/chef/validation.pem <<'EOP' <%= validation_key %> EOP -) > /tmp/validation.pem -awk NF /tmp/validation.pem > /etc/chef/validation.pem -rm /tmp/validation.pem chmod 0600 /etc/chef/validation.pem <% if @chef_config[:encrypted_data_bag_secret] -%> -( -cat <<'EOP' +awk NF > /etc/chef/encrypted_data_bag_secret <<'EOP' <%= encrypted_data_bag_secret %> EOP -) > /tmp/encrypted_data_bag_secret -awk NF /tmp/encrypted_data_bag_secret > /etc/chef/encrypted_data_bag_secret -rm /tmp/encrypted_data_bag_secret chmod 0600 /etc/chef/encrypted_data_bag_secret <% end -%> @@ -37,24 +29,18 @@ chmod 0600 /etc/chef/encrypted_data_bag_secret mkdir -p /etc/chef/ohai/hints <% @chef_config[:knife][:hints].each do |name, hash| -%> -( -cat <<'EOP' +cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' <%= hash.to_json %> EOP -) > /etc/chef/ohai/hints/<%= name %>.json <% end -%> <% end -%> -( -cat <<'EOP' +cat > /etc/chef/client.rb <<'EOP' <%= config_content %> EOP -) > /etc/chef/client.rb -( -cat <<'EOP' +cat > /etc/chef/first-boot.json <<'EOP' <%= first_boot.to_json %> EOP -) > /etc/chef/first-boot.json <%= start_chef %>' diff --git a/lib/chef/knife/cookbook_create.rb b/lib/chef/knife/cookbook_create.rb index c2e92e6b42..1e6797e4e3 100644 --- a/lib/chef/knife/cookbook_create.rb +++ b/lib/chef/knife/cookbook_create.rb @@ -73,10 +73,10 @@ class Chef email = config[:cookbook_email] || "YOUR_EMAIL" license = ((config[:cookbook_license] != "false") && config[:cookbook_license]) || "none" readme_format = ((config[:readme_format] != "false") && config[:readme_format]) || "md" - create_cookbook(cookbook_path,cookbook_name, copyright, license) - create_readme(cookbook_path,cookbook_name,readme_format) - create_changelog(cookbook_path,cookbook_name) - create_metadata(cookbook_path,cookbook_name, copyright, email, license,readme_format) + create_cookbook(cookbook_path, cookbook_name, copyright, license) + create_readme(cookbook_path, cookbook_name, readme_format) + create_changelog(cookbook_path, cookbook_name) + create_metadata(cookbook_path, cookbook_name, copyright, email, license, readme_format) end def create_cookbook(dir, cookbook_name, copyright, license) @@ -193,7 +193,7 @@ This file is used to list changes made in each version of #{cookbook_name}. * Initial release of #{cookbook_name} -- - - +- - - Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. @@ -202,54 +202,203 @@ EOH end end - def create_readme(dir, cookbook_name,readme_format) + def create_readme(dir, cookbook_name, readme_format) msg("** Creating README for cookbook: #{cookbook_name}") unless File.exists?(File.join(dir, cookbook_name, "README.#{readme_format}")) open(File.join(dir, cookbook_name, "README.#{readme_format}"), "w") do |file| case readme_format when "rdoc" file.puts <<-EOH -= DESCRIPTION: - -= REQUIREMENTS: - -= ATTRIBUTES: - -= USAGE: - += #{cookbook_name} Cookbook +TODO: Enter the cookbook description here. + +e.g. +This cookbook makes your favorite breakfast sandwhich. + +== Requirements +TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc. + +e.g. +==== packages +- +toaster+ - #{cookbook_name} needs toaster to brown your bagel. + +== Attributes +TODO: List you cookbook attributes here. + +e.g. +==== #{cookbook_name}::default +<table> + <tr> + <th>Key</th> + <th>Type</th> + <th>Description</th> + <th>Default</th> + </tr> + <tr> + <td><tt>['#{cookbook_name}']['bacon']</tt></td> + <td>Boolean</td> + <td>whether to include bacon</td> + <td><tt>true</tt></td> + </tr> +</table> + +== Usage +==== #{cookbook_name}::default +TODO: Write usage instructions for each cookbook. + +e.g. +Just include +#{cookbook_name}+ in your node's +run_list+: + + { + "name":"my_node", + "run_list": [ + "recipe[#{cookbook_name}]" + ] + } + +== Contributing +TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section. + +e.g. +1. Fork the repository on Github +2. Create a named feature branch (like `add_component_x`) +3. Write you change +4. Write tests for your change (if applicable) +5. Run the tests, ensuring they all pass +6. Submit a Pull Request using Github + +== License and Authors +Authors: TODO: List authors EOH when "md","mkd","txt" file.puts <<-EOH -Description -=========== +#{cookbook_name} Cookbook +#{'='*"#{cookbook_name} Cookbook".length} +TODO: Enter the cookbook description here. + +e.g. +This cookbook makes your favorite breakfast sandwhich. Requirements -============ +------------ +TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc. + +e.g. +#### packages +- `toaster` - #{cookbook_name} needs toaster to brown your bagel. Attributes -========== +---------- +TODO: List you cookbook attributes here. + +e.g. +#### #{cookbook_name}::default +<table> + <tr> + <th>Key</th> + <th>Type</th> + <th>Description</th> + <th>Default</th> + </tr> + <tr> + <td><tt>['#{cookbook_name}']['bacon']</tt></td> + <td>Boolean</td> + <td>whether to include bacon</td> + <td><tt>true</tt></td> + </tr> +</table> Usage -===== - +----- +#### #{cookbook_name}::default +TODO: Write usage instructions for each cookbook. + +e.g. +Just include `#{cookbook_name}` in your node's `run_list`: + +```json +{ + "name":"my_node", + "run_list": [ + "recipe[#{cookbook_name}]" + ] +} +``` + +Contributing +------------ +TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section. + +e.g. +1. Fork the repository on Github +2. Create a named feature branch (like `add_component_x`) +3. Write you change +4. Write tests for your change (if applicable) +5. Run the tests, ensuring they all pass +6. Submit a Pull Request using Github + +License and Authors +------------------- +Authors: TODO: List authors EOH else file.puts <<-EOH -Description +#{cookbook_name} Cookbook +#{'='*"#{cookbook_name} Cookbook".length} + TODO: Enter the cookbook description here. + + e.g. + This cookbook makes your favorite breakfast sandwhich. Requirements + TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc. + + e.g. + toaster #{cookbook_name} needs toaster to brown your bagel. Attributes + TODO: List you cookbook attributes here. -Usage + #{cookbook_name} + Key Type Description Default + ['#{cookbook_name}']['bacon'] Boolean whether to include bacon true +Usage + #{cookbook_name} + TODO: Write usage instructions for each cookbook. + + e.g. + Just include `#{cookbook_name}` in your node's `run_list`: + + [code] + { + "name":"my_node", + "run_list": [ + "recipe[#{cookbook_name}]" + ] + } + [/code] + +Contributing + TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section. + + e.g. + 1. Fork the repository on Github + 2. Create a named feature branch (like `add_component_x`) + 3. Write you change + 4. Write tests for your change (if applicable) + 5. Run the tests, ensuring they all pass + 6. Submit a Pull Request using Github + +License and Authors + Authors: TODO: List authors EOH end end end end - def create_metadata(dir, cookbook_name, copyright, email, license,readme_format) + def create_metadata(dir, cookbook_name, copyright, email, license, readme_format) msg("** Creating metadata for cookbook: #{cookbook_name}") license_name = case license @@ -271,12 +420,13 @@ EOH long_description = "long_description IO.read(File.join(File.dirname(__FILE__), 'README.#{readme_format}'))" end file.puts <<-EOH -maintainer "#{copyright}" -maintainer_email "#{email}" -license "#{license_name}" -description "Installs/Configures #{cookbook_name}" +name '#{cookbook_name}' +maintainer '#{copyright}' +maintainer_email '#{email}' +license '#{license_name}' +description 'Installs/Configures #{cookbook_name}' #{long_description} -version "0.1.0" +version '0.1.0' EOH end end diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb index 46ea8e683e..0d3ff36867 100644 --- a/lib/chef/knife/core/bootstrap_context.rb +++ b/lib/chef/knife/core/bootstrap_context.rb @@ -47,11 +47,11 @@ class Chef end def validation_key - IO.read(@chef_config[:validation_key]) + IO.read(File.expand_path(@chef_config[:validation_key])) end def encrypted_data_bag_secret - IO.read(@chef_config[:encrypted_data_bag_secret]) + IO.read(File.expand_path(@chef_config[:encrypted_data_bag_secret])) end def config_content diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index 481d97c1e7..100fee9fef 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -72,13 +72,13 @@ class Chef :short => "-p PORT", :long => "--ssh-port PORT", :description => "The ssh port", - :proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key } + :proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key.strip } option :ssh_gateway, :short => "-G GATEWAY", :long => "--ssh-gateway GATEWAY", :description => "The ssh gateway", - :proc => Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key } + :proc => Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key.strip } option :identity_file, :short => "-i IDENTITY_FILE", @@ -114,6 +114,22 @@ class Chef @session ||= Net::SSH::Multi.start(:concurrent_connections => config[:concurrency], :on_error => ssh_error_handler) end + def configure_gateway + config[:ssh_gateway] ||= Chef::Config[:knife][:ssh_gateway] + if config[:ssh_gateway] + gw_host, gw_user = config[:ssh_gateway].split('@').reverse + gw_host, gw_port = gw_host.split(':') + gw_opts = gw_port ? { :port => gw_port } : {} + + session.via(gw_host, gw_user || config[:ssh_user], gw_opts) + end + rescue Net::SSH::AuthenticationFailed + user = gw_user || config[:ssh_user] + prompt = "Enter the password for #{user}@#{gw_host}: " + gw_opts.merge!(:password => prompt_for_password(prompt)) + session.via(gw_host, user, gw_opts) + end + def configure_session list = case config[:manual] when true @@ -154,15 +170,6 @@ class Chef end def session_from_list(list) - config[:ssh_gateway] ||= Chef::Config[:knife][:ssh_gateway] - if config[:ssh_gateway] - gw_host, gw_user = config[:ssh_gateway].split('@').reverse - gw_host, gw_port = gw_host.split(':') - gw_opts = gw_port ? { :port => gw_port } : {} - - session.via(gw_host, gw_user || config[:ssh_user], gw_opts) - end - list.each do |item| Chef::Log.debug("Adding #{item}") session_opts = {} @@ -230,7 +237,11 @@ class Chef end def get_password - @password ||= ui.ask("Enter your password: ") { |q| q.echo = false } + @password ||= prompt_for_password + end + + def prompt_for_password(prompt = "Enter your password: ") + ui.ask(prompt) { |q| q.echo = false } end # Present the prompt and read a single line from the console. It also @@ -416,6 +427,7 @@ class Chef configure_attribute configure_user configure_identity_file + configure_gateway configure_session exit_status = diff --git a/lib/chef/provider/log.rb b/lib/chef/provider/log.rb index 5d0417ebda..927ee72fcc 100644 --- a/lib/chef/provider/log.rb +++ b/lib/chef/provider/log.rb @@ -38,7 +38,7 @@ class Chef # === Return # true:: Always return true def action_write - Chef::Log.send(@new_resource.level, @new_resource.name) + Chef::Log.send(@new_resource.level, @new_resource.message) @new_resource.updated_by_last_action(true) end diff --git a/lib/chef/provider/package/yum-dump.py b/lib/chef/provider/package/yum-dump.py index 99136eceec..407eb8f408 100644 --- a/lib/chef/provider/package/yum-dump.py +++ b/lib/chef/provider/package/yum-dump.py @@ -107,6 +107,14 @@ def setup(yb, options): elif YUM_MAJOR == 2: yb.conf.setConfigOption('cache', options.cache) + # Handle repo toggle via id or glob exactly like yum + for opt, repos in options.repo_control: + for repo in repos: + if opt == '--enablerepo': + yb.repos.enableRepo(repo) + elif opt == '--disablerepo': + yb.repos.disableRepo(repo) + return 0 def dump_packages(yb, list, output_provides): @@ -239,6 +247,12 @@ def yum_dump(options): print >> sys.stderr, "yum-dump Unlock Error: %s" % e return 200 +# Preserve order of enable/disable repo args like yum does +def gather_repo_opts(option, opt, value, parser): + if getattr(parser.values, option.dest, None) is None: + setattr(parser.values, option.dest, []) + getattr(parser.values, option.dest).append((opt, value.split(','))) + def main(): usage = "Usage: %prog [options]\n" + \ "Output a list of installed, available and re-installable packages via yum" @@ -261,6 +275,12 @@ def main(): parser.add_option("-a", "--available", action="store_const", const="available", dest="package_list", default="all", help="output only available and re-installable packages") + parser.add_option("--enablerepo", + action="callback", callback=gather_repo_opts, type="string", dest="repo_control", default=[], + help="enable disabled repositories by id or glob") + parser.add_option("--disablerepo", + action="callback", callback=gather_repo_opts, type="string", dest="repo_control", default=[], + help="disable repositories by id or glob") (options, args) = parser.parse_args() diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb index 9048048b83..f67262ef6f 100644 --- a/lib/chef/provider/package/yum.rb +++ b/lib/chef/provider/package/yum.rb @@ -664,12 +664,16 @@ class Chef @allow_multi_install = [] + @extra_repo_control = nil + # these are for subsequent runs if we are on an interval Chef::Client.when_run_starts do YumCache.instance.reload end end + attr_reader :extra_repo_control + # Cache management # @@ -693,6 +697,10 @@ class Chef raise ArgumentError, "Unexpected value in next_refresh: #{@next_refresh}" end + if @extra_repo_control + opts << " #{@extra_repo_control}" + end + one_line = false error = nil @@ -848,6 +856,22 @@ class Chef @allow_multi_install end + def enable_extra_repo_control(arg) + # Don't touch cache if it's the same repos as the last load + unless @extra_repo_control == arg + @extra_repo_control = arg + reload + end + end + + def disable_extra_repo_control + # Only force reload when set + if @extra_repo_control + @extra_repo_control = nil + reload + end + end + private def version(package_name, arch=nil, is_available=false, is_installed=false) @@ -995,6 +1019,23 @@ class Chef @yum.reload end + if @new_resource.options + repo_control = [] + @new_resource.options.split.each do |opt| + if opt =~ %r{--(enable|disable)repo=.+} + repo_control << opt + end + end + + if repo_control.size > 0 + @yum.enable_extra_repo_control(repo_control.join(" ")) + else + @yum.disable_extra_repo_control + end + else + @yum.disable_extra_repo_control + end + # At this point package_name could be: # # 1) a package name, eg: "foo" diff --git a/lib/chef/provider/template.rb b/lib/chef/provider/template.rb index fbd5c600b9..6df671c8e5 100644 --- a/lib/chef/provider/template.rb +++ b/lib/chef/provider/template.rb @@ -66,7 +66,7 @@ class Chef description << diff_current(rendered_template.path) converge_by(description) do backup - FileUtils.mv(rendered_template.path, @new_resource.path) + FileUtils.cp(rendered_template.path, @new_resource.path) Chef::Log.info("#{@new_resource} updated content") access_controls.set_all! update_new_file_state(@new_resource.path) diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 095a07c2e0..f3dabc5b28 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -266,9 +266,13 @@ F def load_prior_resource begin prior_resource = run_context.resource_collection.lookup(self.to_s) - Chef::Log.debug("Setting #{self.to_s} to the state of the prior #{self.to_s}") + # if we get here, there is a prior resource (otherwise we'd have jumped + # to the rescue clause). + Chef::Log.warn("Cloning resource attributes for #{self.to_s} from prior resource (CHEF-3694)") + Chef::Log.warn("Previous #{prior_resource}: #{prior_resource.source_line}") if prior_resource.source_line + Chef::Log.warn("Current #{self}: #{self.source_line}") if self.source_line prior_resource.instance_variables.each do |iv| - unless iv.to_sym == :@source_line || iv.to_sym == :@action + unless iv.to_sym == :@source_line || iv.to_sym == :@action || iv.to_sym == :@not_if || iv.to_sym == :@only_if self.instance_variable_set(iv, prior_resource.instance_variable_get(iv)) end end diff --git a/lib/chef/resource/log.rb b/lib/chef/resource/log.rb index d1b6b5af0b..30a5bb93c6 100644 --- a/lib/chef/resource/log.rb +++ b/lib/chef/resource/log.rb @@ -20,7 +20,7 @@ class Chef class Resource class Log < Chef::Resource - identity_attr :name + identity_attr :message # Sends a string from a recipe to a log provider # @@ -47,6 +47,15 @@ class Chef @resource_name = :log @level = :info @action = :write + @message = name + end + + def message(arg=nil) + set_or_return( + :message, + arg, + :kind_of => String + ) end # <Symbol> Log level, one of :debug, :info, :warn, :error or :fatal diff --git a/lib/chef/rest.rb b/lib/chef/rest.rb index b1f9063f25..21be437e24 100644 --- a/lib/chef/rest.rb +++ b/lib/chef/rest.rb @@ -369,7 +369,6 @@ class Chef Chef::Log.debug("Streaming download from #{url.to_s} to tempfile #{tf.path}") # Stolen from http://www.ruby-forum.com/topic/166423 # Kudos to _why! - size = 0 inflater = if gzip_disabled? NoopInflater.new @@ -388,7 +387,6 @@ class Chef response.read_body do |chunk| tf.write(inflater.inflate(chunk)) - size += chunk.size end tf.close tf |