diff options
Diffstat (limited to 'lib/chef/knife')
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 6 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/archlinux-gems.erb | 25 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/centos5-gems.erb | 39 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/chef-full.erb | 31 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/fedora13-gems.erb | 24 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/ubuntu10.04-apt.erb | 20 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/ubuntu10.04-gems.erb | 31 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/ubuntu12.04-gems.erb | 24 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_create.rb | 206 | ||||
-rw-r--r-- | lib/chef/knife/core/bootstrap_context.rb | 4 | ||||
-rw-r--r-- | lib/chef/knife/ssh.rb | 36 |
11 files changed, 258 insertions, 188 deletions
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 = |