diff options
author | Bryan McLellan <btm@opscode.com> | 2012-10-16 09:29:30 -0700 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2012-10-16 09:29:30 -0700 |
commit | 81bef0f1a7f1ff476159eda5d69185e2c14efc69 (patch) | |
tree | 3ae2ab66876fb6f2aa98094c398aed53aa076c77 /chef/lib/chef/knife | |
parent | 5f5da8f9fa7ed3ab8ab664d8d26919c8c258a2cc (diff) | |
parent | 2f6eae7d03d181fd9cbd0b6e27d39a1cc28804e9 (diff) | |
download | chef-81bef0f1a7f1ff476159eda5d69185e2c14efc69.tar.gz |
Merge branch '10-stable'
Conflicts:
chef-server-webui/lib/chef-server-webui/version.rb
chef-solr/lib/chef/solr/version.rb
chef/lib/chef/chef_fs/file_system/nonexistent_fs_object.rb
chef/lib/chef/knife/ssh.rb
chef/lib/chef/resource/ruby_block.rb
chef/spec/unit/client_spec.rb
chef/spec/unit/cookbook_loader_spec.rb
chef/spec/unit/resource/ruby_block_spec.rb
Diffstat (limited to 'chef/lib/chef/knife')
-rw-r--r-- | chef/lib/chef/knife/bootstrap/archlinux-gems.erb | 2 | ||||
-rw-r--r-- | chef/lib/chef/knife/bootstrap/centos5-gems.erb | 2 | ||||
-rw-r--r-- | chef/lib/chef/knife/bootstrap/chef-full.erb | 3 | ||||
-rw-r--r-- | chef/lib/chef/knife/bootstrap/fedora13-gems.erb | 2 | ||||
-rw-r--r-- | chef/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb | 2 | ||||
-rw-r--r-- | chef/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb | 2 | ||||
-rw-r--r-- | chef/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb | 2 | ||||
-rw-r--r-- | chef/lib/chef/knife/configure.rb | 19 | ||||
-rw-r--r-- | chef/lib/chef/knife/data_bag_edit.rb | 2 | ||||
-rw-r--r-- | chef/lib/chef/knife/data_bag_from_file.rb | 2 | ||||
-rw-r--r-- | chef/lib/chef/knife/environment_from_file.rb | 49 | ||||
-rw-r--r-- | chef/lib/chef/knife/ssh.rb | 18 |
12 files changed, 91 insertions, 14 deletions
diff --git a/chef/lib/chef/knife/bootstrap/archlinux-gems.erb b/chef/lib/chef/knife/bootstrap/archlinux-gems.erb index 6dd57cc64d..85d6236197 100644 --- a/chef/lib/chef/knife/bootstrap/archlinux-gems.erb +++ b/chef/lib/chef/knife/bootstrap/archlinux-gems.erb @@ -17,6 +17,7 @@ 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] -%> ( @@ -26,6 +27,7 @@ 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 -%> <%# Generate Ohai Hints -%> diff --git a/chef/lib/chef/knife/bootstrap/centos5-gems.erb b/chef/lib/chef/knife/bootstrap/centos5-gems.erb index 2b1b1816fe..f9626c3c2b 100644 --- a/chef/lib/chef/knife/bootstrap/centos5-gems.erb +++ b/chef/lib/chef/knife/bootstrap/centos5-gems.erb @@ -30,6 +30,7 @@ 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] -%> ( @@ -39,6 +40,7 @@ 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 -%> <%# Generate Ohai Hints -%> diff --git a/chef/lib/chef/knife/bootstrap/chef-full.erb b/chef/lib/chef/knife/bootstrap/chef-full.erb index c02245690d..771ef85884 100644 --- a/chef/lib/chef/knife/bootstrap/chef-full.erb +++ b/chef/lib/chef/knife/bootstrap/chef-full.erb @@ -32,7 +32,7 @@ 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] -%> ( @@ -42,6 +42,7 @@ 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 -%> <%# Generate Ohai Hints -%> diff --git a/chef/lib/chef/knife/bootstrap/fedora13-gems.erb b/chef/lib/chef/knife/bootstrap/fedora13-gems.erb index a216b4e313..a8448342df 100644 --- a/chef/lib/chef/knife/bootstrap/fedora13-gems.erb +++ b/chef/lib/chef/knife/bootstrap/fedora13-gems.erb @@ -17,6 +17,7 @@ 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] -%> ( @@ -26,6 +27,7 @@ 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 -%> <%# Generate Ohai Hints -%> diff --git a/chef/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb b/chef/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb index 14a924e032..0e44361d82 100644 --- a/chef/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +++ b/chef/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb @@ -17,6 +17,7 @@ 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] -%> ( @@ -26,6 +27,7 @@ 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 -%> <%# Generate Ohai Hints -%> diff --git a/chef/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb b/chef/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb index 88dcc48286..63448fc4d3 100644 --- a/chef/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +++ b/chef/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb @@ -24,6 +24,7 @@ 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] -%> ( @@ -33,6 +34,7 @@ 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 -%> <%# Generate Ohai Hints -%> diff --git a/chef/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb b/chef/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb index df128300db..e7da7db39b 100644 --- a/chef/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +++ b/chef/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb @@ -19,6 +19,7 @@ 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] -%> ( @@ -28,6 +29,7 @@ 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 -%> <%# Generate Ohai Hints -%> diff --git a/chef/lib/chef/knife/configure.rb b/chef/lib/chef/knife/configure.rb index 0526244053..0be7093e29 100644 --- a/chef/lib/chef/knife/configure.rb +++ b/chef/lib/chef/knife/configure.rb @@ -42,6 +42,22 @@ class Chef :boolean => true, :description => "Create an initial API Client" + option :admin_client_name, + :long => "--admin-client-name NAME", + :description => "The existing admin clientname (usually chef-webui)" + + option :admin_client_key, + :long => "--admin-client-key PATH", + :description => "The path to the admin client's private key (usually a file named webui.pem)" + + option :validation_client_name, + :long => "--validation-client-name NAME", + :description => "The validation clientname (usually chef-validator)" + + option :validation_key, + :long => "--validation-key PATH", + :description => "The location of the location of the validation key (usually a file named validation.pem)" + def configure_chef # We are just faking out the system so that you can do this without a key specified Chef::Config[:node_name] = 'woot' @@ -120,14 +136,17 @@ EOH @new_client_name = config[:node_name] || ask_question("Please enter a clientname for the new client: ", :default => Etc.getlogin) @admin_client_name = config[:admin_client_name] || ask_question("Please enter the existing admin clientname: ", :default => 'chef-webui') @admin_client_key = config[:admin_client_key] || ask_question("Please enter the location of the existing admin client's private key: ", :default => '/etc/chef/webui.pem') + @admin_client_key = File.expand_path(@admin_client_key) else @new_client_name = config[:node_name] || ask_question("Please enter an existing username or clientname for the API: ", :default => Etc.getlogin) end @validation_client_name = config[:validation_client_name] || ask_question("Please enter the validation clientname: ", :default => 'chef-validator') @validation_key = config[:validation_key] || ask_question("Please enter the location of the validation key: ", :default => '/etc/chef/validation.pem') + @validation_key = File.expand_path(@validation_key) @chef_repo = config[:repository] || ask_question("Please enter the path to a chef repository (or leave blank): ") @new_client_key = config[:client_key] || File.join(chef_config_path, "#{@new_client_name}.pem") + @new_client_key = File.expand_path(@new_client_key) end def guess_servername diff --git a/chef/lib/chef/knife/data_bag_edit.rb b/chef/lib/chef/knife/data_bag_edit.rb index 9ea9e5d282..234c77177d 100644 --- a/chef/lib/chef/knife/data_bag_edit.rb +++ b/chef/lib/chef/knife/data_bag_edit.rb @@ -84,7 +84,7 @@ class Chef output = edit_item(item) rest.put_rest("data/#{@name_args[0]}/#{@name_args[1]}", output) stdout.puts("Saved data_bag_item[#{@name_args[1]}]") - output(format_for_display(object.raw_data)) if config[:print_after] + ui.output(output) if config[:print_after] end end end diff --git a/chef/lib/chef/knife/data_bag_from_file.rb b/chef/lib/chef/knife/data_bag_from_file.rb index 4d26548c5e..275cbeac52 100644 --- a/chef/lib/chef/knife/data_bag_from_file.rb +++ b/chef/lib/chef/knife/data_bag_from_file.rb @@ -46,7 +46,7 @@ class Chef option :all, :short => "-a", :long => "--all", - :description => "Upload all data bags" + :description => "Upload all data bags or all items for specified data bags" def read_secret if config[:secret] diff --git a/chef/lib/chef/knife/environment_from_file.rb b/chef/lib/chef/knife/environment_from_file.rb index 5a0ce8bef4..af72f84622 100644 --- a/chef/lib/chef/knife/environment_from_file.rb +++ b/chef/lib/chef/knife/environment_from_file.rb @@ -25,26 +25,59 @@ class Chef require 'chef/knife/core/object_loader' end - banner "knife environment from file FILE (options)" + banner "knife environment from file FILE [FILE..] (options)" + + option :all, + :short => "-a", + :long => "--all", + :description => "Upload all environments" def loader @loader ||= Knife::Core::ObjectLoader.new(Chef::Environment, ui) end + def environments_path + @environments_path ||= "environments" + end - def run - if @name_args[0].nil? - show_usage - ui.fatal("You must specify a file to load") - exit 1 - end + def find_all_environments + loader.find_all_objects("./#{environments_path}/") + end + def load_all_environments + environments = find_all_environments + if environments.empty? + ui.fatal("Unable to find any environment files in '#{environments_path}'") + exit(1) + end + environments.each do |env| + load_environment(env) + end + end - updated = loader.load_from("environments", @name_args[0]) + def load_environment(env) + updated = loader.load_from("environments", env) updated.save output(format_for_display(updated)) if config[:print_after] ui.info("Updated Environment #{updated.name}") end + + + def run + if config[:all] == true + load_all_environments + else + if @name_args[0].nil? + show_usage + ui.fatal("You must specify a file to load") + exit 1 + end + + @name_args.each do |arg| + load_environment(arg) + end + end + end end end end diff --git a/chef/lib/chef/knife/ssh.rb b/chef/lib/chef/knife/ssh.rb index d3aafc73f8..a1b37723a6 100644 --- a/chef/lib/chef/knife/ssh.rb +++ b/chef/lib/chef/knife/ssh.rb @@ -124,7 +124,8 @@ class Chef q = Chef::Search::Query.new @action_nodes = q.search(:node, @name_args[0])[0] @action_nodes.each do |item| - + # we should skip the loop to next iteration if the item returned by the search is nil + next if item.nil? # if a command line attribute was not passed, and we have a cloud public_hostname, use that. # see #configure_attribute for the source of config[:attribute] and config[:override_attribute] if !config[:override_attribute] && item[:cloud] and item[:cloud][:public_hostname] @@ -134,11 +135,22 @@ class Chef else i = extract_nested_value(item, config[:attribute]) end - r.push(i) unless i.nil? + # next if we couldn't find the specified attribute in the returned node object + next if i.nil? + r.push(i) end r end - (ui.fatal("No nodes returned from search!"); exit 10) if list.length == 0 + if list.length == 0 + if @action_nodes.length == 0 + ui.fatal("No nodes returned from search!") + else + ui.fatal("#{@action_nodes.length} #{@action_nodes.length > 1 ? "nodes":"node"} found, " + + "but do not have the required attribute to stablish the connection. " + + "Try setting another attribute to open the connection using --attribute.") + end + exit 10 + end session_from_list(list) end |