From c2bdd7d970401fb3e7e3d9ec1439844b5bc57947 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 14 Feb 2013 09:47:36 -0500 Subject: [PATCH 01/33] A first cut at generating solo.rb from knife.rb thoughts @tmatilai? --- knife-solo.gemspec | 5 +++-- lib/knife-solo/config.rb | 12 ++++++++++++ lib/knife-solo/resources/solo.rb.erb | 5 +++++ test/knife-solo/config_test.rb | 20 ++++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 lib/knife-solo/resources/solo.rb.erb diff --git a/knife-solo.gemspec b/knife-solo.gemspec index 0bad3af0..ae9b4d8f 100644 --- a/knife-solo.gemspec +++ b/knife-solo.gemspec @@ -31,7 +31,8 @@ Gem::Specification.new do |s| s.add_development_dependency 'minitest' s.add_development_dependency 'parallel' - s.add_dependency 'chef', chef_version - s.add_dependency 'net-ssh', '>= 2.2.2', '< 3.0' + s.add_dependency 'chef', chef_version + s.add_dependency 'net-ssh', '>= 2.2.2', '< 3.0' s.add_dependency 'librarian', '~> 0.0.20' + s.add_dependency 'erubis', '~> 2.7.0' end diff --git a/lib/knife-solo/config.rb b/lib/knife-solo/config.rb index 190503fa..7e159192 100644 --- a/lib/knife-solo/config.rb +++ b/lib/knife-solo/config.rb @@ -1,4 +1,6 @@ require 'chef/config' +require 'knife-solo' +require 'erubis' module KnifeSolo # Encapsulates some logic for checking and extracting @@ -13,6 +15,16 @@ def chef_path solo_path || './chef-solo' end + def knife_solo_config + Chef::Config.knife[:solo] + end + + def solo_rb + config = Chef::Config.knife[:solo] + path = config.delete(:path) || './chef-solo' + Erubis::Eruby.new(KnifeSolo.resource('solo.rb.erb').read).result(binding) + end + def cookbook_path if using_custom_solorb? Chef::Config.from_file('solo.rb') diff --git a/lib/knife-solo/resources/solo.rb.erb b/lib/knife-solo/resources/solo.rb.erb new file mode 100644 index 00000000..3a7837dc --- /dev/null +++ b/lib/knife-solo/resources/solo.rb.erb @@ -0,0 +1,5 @@ +base = File.expand_path('..', __FILE__) + +<% config.each do |key, value| %> + <%= key %>(<%= value.inspect %>) +<% end %> diff --git a/test/knife-solo/config_test.rb b/test/knife-solo/config_test.rb index f5baba6c..2340ef65 100644 --- a/test/knife-solo/config_test.rb +++ b/test/knife-solo/config_test.rb @@ -12,6 +12,26 @@ def teardown FileUtils.rm_f 'solo.rb' end + def test_can_generate_solorb_from_knife_configs + Chef::Config.knife[:solo] = { + :file_cache_path => "/custom/cache/path", + :data_bag_path => "/custom/data_bag/path", + :encrypted_data_bag_secret => "/custom/secret/path", + :role_path => "/custom/role/path", + :cookbook_path => [ "/custom/cookbook/path1", "/custom/cookbook/path2" ] + } + + write_file('solo.rb', @config.solo_rb) + Chef::Config.from_file('solo.rb') + + assert_equal "/custom/cache/path", Chef::Config.file_cache_path + assert_equal "/custom/data_bag/path", Chef::Config.data_bag_path + assert_equal "/custom/secret/path", Chef::Config.encrypted_data_bag_secret + assert_equal "/custom/role/path", Chef::Config.role_path + assert Chef::Config.cookbook_path.include?("/custom/cookbook/path1") && + Chef::Config.cookbook_path.include?("/custom/cookbook/path2") + end + def test_uses_cookbook_path_from_solo_rb_if_available write_file('solo.rb', <<-RUBY) knife[:solo_path] = "./custom" From 93457f61688a353955056f41aa97efef73deafb4 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 14 Feb 2013 13:08:45 -0500 Subject: [PATCH 02/33] Automatically expanding relative paths in solo.rb --- lib/knife-solo/config.rb | 13 +++++++++++++ lib/knife-solo/resources/solo.rb.erb | 2 +- test/knife-solo/config_test.rb | 10 ++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/knife-solo/config.rb b/lib/knife-solo/config.rb index 7e159192..7f81c9ff 100644 --- a/lib/knife-solo/config.rb +++ b/lib/knife-solo/config.rb @@ -19,6 +19,19 @@ def knife_solo_config Chef::Config.knife[:solo] end + def process_path(path) + if path[0] == '.' + "base + #{path[1..-1].inspect}" + else + path.inspect + end + end + + def process_paths(paths) + return process_path(paths) unless paths.is_a? Array + "[" + paths.map { |path| process_path(path) }.join(',') + "]" + end + def solo_rb config = Chef::Config.knife[:solo] path = config.delete(:path) || './chef-solo' diff --git a/lib/knife-solo/resources/solo.rb.erb b/lib/knife-solo/resources/solo.rb.erb index 3a7837dc..f0ad15a8 100644 --- a/lib/knife-solo/resources/solo.rb.erb +++ b/lib/knife-solo/resources/solo.rb.erb @@ -1,5 +1,5 @@ base = File.expand_path('..', __FILE__) <% config.each do |key, value| %> - <%= key %>(<%= value.inspect %>) + <%= key %>(<%= process_paths(value) %>) <% end %> diff --git a/test/knife-solo/config_test.rb b/test/knife-solo/config_test.rb index 2340ef65..c0ba33c3 100644 --- a/test/knife-solo/config_test.rb +++ b/test/knife-solo/config_test.rb @@ -32,6 +32,15 @@ def test_can_generate_solorb_from_knife_configs Chef::Config.cookbook_path.include?("/custom/cookbook/path2") end + def test_expands_paths_relative_to_file + Chef::Config.knife[:solo] = { :data_bag_path => './data_bags', + :cookbook_path => ['./cookbooks'] } + write_file('solo.rb', @config.solo_rb) + Chef::Config.from_file('solo.rb') + assert_equal File.expand_path('../../../data_bags', __FILE__), + Chef::Config.data_bag_path + end + def test_uses_cookbook_path_from_solo_rb_if_available write_file('solo.rb', <<-RUBY) knife[:solo_path] = "./custom" @@ -41,6 +50,7 @@ def test_uses_cookbook_path_from_solo_rb_if_available end def test_reads_chef_root_path_from_knife_config_or_defaults_to_home + Chef::Config.knife[:solo_path] = nil assert_equal './chef-solo', @config.chef_path Chef::Config.knife[:solo_path] = "/tmp/custom-chef-solo" assert_equal "/tmp/custom-chef-solo", @config.chef_path From dd5a7472c66f5efeeeadeab4085974223d3f379c Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Thu, 14 Feb 2013 13:09:11 -0500 Subject: [PATCH 03/33] Manifest update --- Manifest.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Manifest.txt b/Manifest.txt index 55dd2f73..f580c00c 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -25,6 +25,7 @@ lib/knife-solo/gitignore.rb lib/knife-solo/info.rb lib/knife-solo/node_config_command.rb lib/knife-solo/resources/solo.rb +lib/knife-solo/resources/solo.rb.erb lib/knife-solo/ssh_command.rb lib/knife-solo/tools.rb test/bootstraps_test.rb From 9e04f88152a2ef068e726ec51ec0e5d681e328a7 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Sat, 2 Mar 2013 11:50:29 -0500 Subject: [PATCH 04/33] WIP: Using knife.rb to configure and generate solo.rb --- .gitmodules | 3 + lib/chef/knife/patches/parser.rb | 223 ------------------ lib/chef/knife/patches/search.rb | 110 --------- lib/chef/knife/solo_cook.rb | 86 ++++--- lib/chef/knife/solo_init.rb | 8 + lib/knife-solo/resources/knife.rb | 10 + .../resources/patch_cookbook/chef-solo-search | 1 + lib/knife-solo/resources/solo.rb | 6 - lib/knife-solo/resources/solo.rb.erb | 9 +- 9 files changed, 85 insertions(+), 371 deletions(-) create mode 100644 .gitmodules delete mode 100644 lib/chef/knife/patches/parser.rb delete mode 100644 lib/chef/knife/patches/search.rb create mode 100644 lib/knife-solo/resources/knife.rb create mode 160000 lib/knife-solo/resources/patch_cookbook/chef-solo-search delete mode 100644 lib/knife-solo/resources/solo.rb diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..55f71f03 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/knife-solo/resources/patch_cookbook/chef-solo-search"] + path = lib/knife-solo/resources/patch_cookbook/chef-solo-search + url = https://github.com/edelight/chef-solo-search.git diff --git a/lib/chef/knife/patches/parser.rb b/lib/chef/knife/patches/parser.rb deleted file mode 100644 index 69b07e61..00000000 --- a/lib/chef/knife/patches/parser.rb +++ /dev/null @@ -1,223 +0,0 @@ -# -# Copyright 2011, edelight GmbH -# -# Authors: -# Markus Korn -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require 'treetop' -require 'chef/solr_query/query_transform' - -# mock QueryTransform such that we can access the location of the lucene grammar -class Chef - class SolrQuery - class QueryTransform - def self.base_path - class_variable_get(:@@base_path) - end - end - end -end - -def build_flat_hash(hsh, prefix="") - result = {} - hsh.each_pair do |key, value| - if value.kind_of?(Hash) - result.merge!(build_flat_hash(value, "#{prefix}#{key}_")) - else - result[prefix+key] = value - end - end - result -end - -module Lucene - - class Term < Treetop::Runtime::SyntaxNode - # compares a query value and a value, tailing '*'-wildcards are handled correctly. - # Value can either be a string or an array, all other objects are converted - # to a string and than checked. - def match( value ) - if value.is_a?(Array) - value.any?{ |x| self.match(x) } - else - File.fnmatch(self.text_value, value.to_s) - end - end - end - - class Field < Treetop::Runtime::SyntaxNode - # simple field -> value matches, supporting tailing '*'-wildcards in keys - # as well as in values - def match( item ) - keys = self.elements[0].match(item) - if keys.nil? - false - else - keys.any?{ |key| self.elements[1].match(item[key]) } - end - end - end - - # we don't support range matches - # range of integers would be easy to implement - # but string ranges are hard - class FiledRange < Treetop::Runtime::SyntaxNode - end - - # we handle '[* TO *]' as a special case since it is common in - # cookbooks for matching the existence of keys - class InclFieldRange - def match(item) - field = self.elements[0].text_value - range_start = self.elements[1].transform - range_end = self.elements[2].transform - if range_start == "*" and range_end == "*" - !!item[field] - else - raise "Ranges not really supported yet" - end - end - end - - class ExclFieldRange < FieldRange - end - - class RangeValue < Treetop::Runtime::SyntaxNode - end - - class FieldName < Treetop::Runtime::SyntaxNode - def match( item ) - if self.text_value.count("_") > 0 - item.merge!(build_flat_hash(item)) - end - if self.text_value.end_with?("*") - part = self.text_value.chomp("*") - item.keys.collect{ |key| key.start_with?(part)? key: nil}.compact - else - if item[self.text_value] - [self.text_value,] - else - nil - end - end - end - end - - class Body < Treetop::Runtime::SyntaxNode - def match( item ) - self.elements[0].match( item ) - end - end - - class Group < Treetop::Runtime::SyntaxNode - def match( item ) - self.elements[0].match(item) - end - end - - class BinaryOp < Treetop::Runtime::SyntaxNode - def match( item ) - self.elements[1].match( - self.elements[0].match(item), - self.elements[2].match(item) - ) - end - end - - class OrOperator < Treetop::Runtime::SyntaxNode - def match( cond1, cond2 ) - cond1 or cond2 - end - end - - class AndOperator < Treetop::Runtime::SyntaxNode - def match( cond1, cond2 ) - cond1 and cond2 - end - end - - # we don't support fuzzy string matching - class FuzzyOp < Treetop::Runtime::SyntaxNode - end - - class BoostOp < Treetop::Runtime::SyntaxNode - end - - class FuzzyParam < Treetop::Runtime::SyntaxNode - end - - class UnaryOp < Treetop::Runtime::SyntaxNode - def match( item ) - self.elements[0].match( - self.elements[1].match(item) - ) - end - end - - class NotOperator < Treetop::Runtime::SyntaxNode - def match( cond ) - not cond - end - end - - class RequiredOperator < Treetop::Runtime::SyntaxNode - end - - class ProhibitedOperator < Treetop::Runtime::SyntaxNode - end - - class Phrase < Treetop::Runtime::SyntaxNode - # a quoted ::Term - def match( value ) - self.elements[0].match(value) - end - end -end - -class Query - # initialize the parser by using the grammar shipped with chef - @@grammar = File.join(Chef::SolrQuery::QueryTransform.base_path, "lucene.treetop") - Treetop.load(@@grammar) - @@parser = LuceneParser.new - - def self.parse(data) - # parse the query into a query tree - if data.nil? - data = "*:*" - end - tree = @@parser.parse(data) - if tree.nil? - msg = "Parse error at offset: #{@@parser.index}\n" - msg += "Reason: #{@@parser.failure_reason}" - raise "Query #{data} is not supported: #{msg}" - end - self.clean_tree(tree) - tree - end - - private - - def self.clean_tree(root_node) - # remove all SyntaxNode elements from the tree, we don't need them as - # the related ruby class already knowns what to do. - return if root_node.elements.nil? - root_node.elements.delete_if do |node| - node.class.name == "Treetop::Runtime::SyntaxNode" - end - root_node.elements.each { |node| self.clean_tree(node) } - end -end - diff --git a/lib/chef/knife/patches/search.rb b/lib/chef/knife/patches/search.rb deleted file mode 100644 index b528c716..00000000 --- a/lib/chef/knife/patches/search.rb +++ /dev/null @@ -1,110 +0,0 @@ -# -# Copyright 2011, edelight GmbH -# -# Authors: -# Markus Korn -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -if Chef::Config[:solo] - - if (defined? require_relative).nil? - # defenition of 'require_relative' for ruby < 1.9, found on stackoverflow.com - def require_relative(relative_feature) - c = caller.first - fail "Can't parse #{c}" unless c.rindex(/:\d+(:in `.*')?$/) - file = $` - if /\A\((.*)\)/ =~ file # eval, etc. - raise LoadError, "require_relative is called in #{$1}" - end - absolute = File.expand_path(relative_feature, File.dirname(file)) - require absolute - end - end - - require_relative 'parser.rb' - - class Chef - module Mixin - module Language - - # Overwrite the search method of recipes to operate locally by using - # data found in data_bags. - # Only very basic lucene syntax is supported and also sorting the result - # is not implemented, if this search method does not support a given query - # an exception is raised. - # This search() method returns a block iterator or an Array, depending - # on how this method is called. - def search(obj, query=nil, sort=nil, start=0, rows=1000, &block) - if !sort.nil? - raise "Sorting search results is not supported" - end - @_query = Query.parse(query) - if @_query.nil? - raise "Query #{query} is not supported" - end - @_result = [] - - case obj - when :node - search_nodes(start, rows, &block) - when :role - search_roles(start, rows, &block) - else - search_data_bag(obj, start, rows, &block) - end - - - if block_given? - pos = 0 - while (pos >= start and pos < (start + rows) and pos < @_result.size) - yield @_result[pos] - pos += 1 - end - else - return @_result.slice(start, rows) - end - end - - def search_nodes(start, rows, &block) - Dir.glob(File.join(Chef::Config[:data_bag_path], "node", "*.json")).map do |f| - # parse and hashify the node - node = JSON.parse(IO.read(f)) - if @_query.match(node.to_hash) - @_result << node - end - end - end - - def search_roles(start, rows, &block) - raise "Role searching not implemented" - end - - def search_data_bag(bag_name, start, rows, &block) - secret_path = Chef::Config[:encrypted_data_bag_secret] - data_bag(bag_name.to_s).each do |bag_item_id| - if secret_path && secret = Chef::EncryptedDataBagItem.load_secret(secret_path) - bag_item = Chef::EncryptedDataBagItem.load(bag_name, bag_item_id, secret) - else - bag_item = data_bag_item(bag_name.to_s, bag_item_id) - end - if @_query.match(bag_item) - @_result << bag_item - end - end - end - end - end - end -end diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index eaa60a4a..bda75c16 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -4,7 +4,10 @@ require 'knife-solo/ssh_command' require 'knife-solo/node_config_command' require 'knife-solo/tools' -require 'knife-solo/config' + +require 'tempfile' +require 'erubis' +require 'chef/config' class Chef class Knife @@ -56,9 +59,12 @@ class SoloCook < Knife :long => '--override-runlist', :description => 'Replace current run list with specified items' - def run - @solo_config = KnifeSolo::Config.new + option :provisioning_path, + :long => '--provisioning-path path', + :description => 'Where to store kitchen data on the node', + :default => './chef-solo' + def run time('Run') do if config[:skip_chef_check] @@ -73,21 +79,45 @@ def run check_chef_version if config[:chef_check] generate_node_config librarian_install if config[:librarian] - rsync_kitchen - add_patches - add_solo_config unless using_custom_solorb? + sync_kitchen + generate_solorb cook unless config[:sync_only] end end - def_delegators :@solo_config, - :chef_path, - :using_custom_solorb?, - :patch_path + def provisioning_path + config[:provisioning_path] + end + + def sync_kitchen + run_portable_mkdir_p(provisioning_path) + + cookbook_paths.each do |path| + upload(path, provisioning_path) + end + + upload(role_path, provisioning_path + '/roles') + upload(nodes_path, provisioning_path + '/nodes') + upload(data_bag_path, provisioning_path + '/data_bags') + upload(encrypted_data_bag_secret, provisioning_path + '/data_bag_key') if encrypted_data_bag_secret + end + + # TODO should watch for name collision here + def cookbook_paths + Chef::Config.cookbook_path + [KnifeSolo.resource('patch_cookbooks')] + end + + def nodes_path + 'nodes' + end + + def_delegators 'Chef::Config', + :role_path, + :data_bag_path, + :encrypted_data_bag_secret def validate! validate_ssh_options! - @solo_config.validate! end def chefignore @@ -143,29 +173,27 @@ def librarian_env @librarian_env ||= Librarian::Chef::Environment.new end - def rsync_kitchen - ui.msg "Syncing kitchen..." - time('Rsync kitchen') do - rsync('./', chef_path, '--delete') - end + def generate_solorb + ui.msg "Generating solo config..." + template = Erubis::Eruby.new(KnifeSolo.resource('solo.rb.erb').read) + write(template.result(binding), provisioning_path + '/solo.rb') end - def add_patches - ui.msg "Adding patches..." - run_portable_mkdir_p(patch_path) - Dir[Pathname.new(__FILE__).dirname.join("patches", "*.rb").to_s].each do |patch| - time(patch) do - rsync(patch, patch_path) - end - end + def upload(src, dest) + rsync(src, dest) end - def add_solo_config - ui.msg "Syncing solo config..." - rsync(KnifeSolo.resource('solo.rb'), chef_path) + # TODO probably can get Net::SSH to do this directly + def write(content, dest) + file = Tempfile.new(File.basename(dest)) + file.write(content) + file.close + upload(file.path, dest) + ensure + file.unlink end - def rsync(source_path, target_path, extra_opts = '') + def rsync(source_path, target_path, extra_opts = '--delete') cmd = %Q{rsync -rl #{rsync_permissions} --rsh="ssh #{ssh_args}" #{extra_opts} #{rsync_excludes.collect{ |ignore| "--exclude #{ignore} " }.join} #{adjust_rsync_path_on_client(source_path)} :#{adjust_rsync_path_on_node(target_path)}} ui.msg cmd if debug? system! cmd @@ -186,7 +214,7 @@ def chef_version def cook ui.msg "Running Chef..." - cmd = "sudo chef-solo -c #{chef_path}/solo.rb -j #{chef_path}/#{node_config}" + cmd = "sudo chef-solo -c #{provisioning_path}/solo.rb -j #{provisioning_path}/#{node_config}" cmd << " -l debug" if debug? cmd << " -N #{config[:chef_node_name]}" if config[:chef_node_name] cmd << " -W" if config[:why_run] diff --git a/lib/chef/knife/solo_init.rb b/lib/chef/knife/solo_init.rb index f249c6a4..9628b197 100644 --- a/lib/chef/knife/solo_init.rb +++ b/lib/chef/knife/solo_init.rb @@ -1,4 +1,5 @@ require 'chef/knife' +require 'fileutils' class Chef class Knife @@ -24,6 +25,7 @@ def run @base = @name_args.first validate! create_kitchen + create_config create_cupboards %w[nodes roles data_bags site-cookbooks cookbooks] librarian_init if config[:librarian] end @@ -52,6 +54,12 @@ def create_kitchen mkdir @base unless @base == '.' end + def create_config + ui.msg "Creating knife.rb in kitchen..." + mkdir File.join(@base, '.chef') + FileUtils.cp(KnifeSolo.resource('knife.rb'), File.join(@base, '.chef', 'knife.rb')) + end + def librarian_init ui.msg "Setting up Librarian..." cheffile = File.join(@base, 'Cheffile') diff --git a/lib/knife-solo/resources/knife.rb b/lib/knife-solo/resources/knife.rb new file mode 100644 index 00000000..9f8ab182 --- /dev/null +++ b/lib/knife-solo/resources/knife.rb @@ -0,0 +1,10 @@ +cookbook_path ["cookbooks", "site-cookbooks"] +role_path "roles" +data_bag_path "data_bags" + +# To use encryptd data bags first generate a secret: +# openssl rand -base64 512 | tr -d '\r\n' > data_bag_key +# Then uncomment the line below. + +# encrypted_data_bag_secret "data_bag_key" + diff --git a/lib/knife-solo/resources/patch_cookbook/chef-solo-search b/lib/knife-solo/resources/patch_cookbook/chef-solo-search new file mode 160000 index 00000000..da3cdbdf --- /dev/null +++ b/lib/knife-solo/resources/patch_cookbook/chef-solo-search @@ -0,0 +1 @@ +Subproject commit da3cdbdf3547bc2d9ffb71e2bb58a10723ab6e93 diff --git a/lib/knife-solo/resources/solo.rb b/lib/knife-solo/resources/solo.rb deleted file mode 100644 index ea2b1cfd..00000000 --- a/lib/knife-solo/resources/solo.rb +++ /dev/null @@ -1,6 +0,0 @@ -base = File.expand_path('..', __FILE__) - -data_bag_path base + '/data_bags' -encrypted_data_bag_secret base + '/data_bag_key' -role_path base + '/roles' -cookbook_path [ base + '/site-cookbooks', base + '/cookbooks' ] diff --git a/lib/knife-solo/resources/solo.rb.erb b/lib/knife-solo/resources/solo.rb.erb index f0ad15a8..59e3d9d9 100644 --- a/lib/knife-solo/resources/solo.rb.erb +++ b/lib/knife-solo/resources/solo.rb.erb @@ -1,5 +1,8 @@ base = File.expand_path('..', __FILE__) -<% config.each do |key, value| %> - <%= key %>(<%= process_paths(value) %>) -<% end %> +role_path base + '/roles' +data_bag_path base + '/data_bags' +encrypted_data_bag_secret base + '/data_bag_key' + +cookbook_path [ <%= cookbook_paths.map { |p| "base + '/' + " + File.basename(p).inspect }.join(', ') %> ] + From b742e3170496bb3dd69a9b51516bf8aba133b67f Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Sat, 2 Mar 2013 22:16:11 -0500 Subject: [PATCH 05/33] Include submodules in manifest --- Rakefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index 814632e6..835eee2c 100644 --- a/Rakefile +++ b/Rakefile @@ -5,6 +5,7 @@ require File.join(File.dirname(__FILE__), 'lib', 'knife-solo', 'info') MANIFEST_IGNORES = %w[ .travis.yml .gitignore + .gitmodules Gemfile Gemfile.lock Manifest.txt @@ -24,10 +25,11 @@ namespace :manifest do desc 'Updates Manifest.txt with a list of files from git' task :update do - git_files = `git ls-files`.split("\n") + git_files = `git ls-files`.split("\n") + submodule_files = `git submodule foreach -q 'for f in $(git ls-files); do echo $path/$f; done'`.split("\n") File.open('Manifest.txt', 'w') do |f| - f.puts((git_files - MANIFEST_IGNORES).join("\n")) + f.puts((git_files + submodule_files - MANIFEST_IGNORES).join("\n")) end end end From 9d4a164189d6264a6f56894ad021d27ca8b7ea1f Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Sat, 2 Mar 2013 22:16:21 -0500 Subject: [PATCH 06/33] Update manifest --- Manifest.txt | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Manifest.txt b/Manifest.txt index f580c00c..09ae5b0c 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -4,8 +4,6 @@ README.rdoc Rakefile lib/chef/knife/cook.rb lib/chef/knife/kitchen.rb -lib/chef/knife/patches/parser.rb -lib/chef/knife/patches/search.rb lib/chef/knife/prepare.rb lib/chef/knife/solo_bootstrap.rb lib/chef/knife/solo_clean.rb @@ -24,7 +22,8 @@ lib/knife-solo/deprecated_command.rb lib/knife-solo/gitignore.rb lib/knife-solo/info.rb lib/knife-solo/node_config_command.rb -lib/knife-solo/resources/solo.rb +lib/knife-solo/resources/knife.rb +lib/knife-solo/resources/patch_cookbook/chef-solo-search lib/knife-solo/resources/solo.rb.erb lib/knife-solo/ssh_command.rb lib/knife-solo/tools.rb @@ -74,3 +73,24 @@ test/support/ssh_config test/support/test_case.rb test/support/validation_helper.rb test/test_helper.rb +lib/knife-solo/resources/patch_cookbook/chef-solo-search/CHANGELOG +lib/knife-solo/resources/patch_cookbook/chef-solo-search/LICENSE +lib/knife-solo/resources/patch_cookbook/chef-solo-search/NOTICE +lib/knife-solo/resources/patch_cookbook/chef-solo-search/README.md +lib/knife-solo/resources/patch_cookbook/chef-solo-search/libraries/search.rb +lib/knife-solo/resources/patch_cookbook/chef-solo-search/libraries/search/overrides.rb +lib/knife-solo/resources/patch_cookbook/chef-solo-search/libraries/search/parser.rb +lib/knife-solo/resources/patch_cookbook/chef-solo-search/libraries/vendor/chef/solr_query/lucene.treetop +lib/knife-solo/resources/patch_cookbook/chef-solo-search/libraries/vendor/chef/solr_query/lucene_nodes.rb +lib/knife-solo/resources/patch_cookbook/chef-solo-search/libraries/vendor/chef/solr_query/query_transform.rb +lib/knife-solo/resources/patch_cookbook/chef-solo-search/metadata.rb +lib/knife-solo/resources/patch_cookbook/chef-solo-search/recipes/default.rb +lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/Gemfile +lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/data/data_bags/node/alpha.json +lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/data/data_bags/node/beta.json +lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/data/data_bags/users/jerry.json +lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/data/data_bags/users/lea.json +lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/data/data_bags/users/mike.json +lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/data/data_bags/users/tom.json +lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/test_data_bags.rb +lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/test_search.rb From 4267d21536b047dd07195cd2d0fffa4a5ce9a730 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Sat, 2 Mar 2013 22:19:25 -0500 Subject: [PATCH 07/33] Fix test stub --- test/solo_cook_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/solo_cook_test.rb b/test/solo_cook_test.rb index b99b654c..4870db12 100644 --- a/test/solo_cook_test.rb +++ b/test/solo_cook_test.rb @@ -144,7 +144,7 @@ def assert_chef_solo_option(cook_option, chef_solo_option) def command(*args) cmd = knife_command(Chef::Knife::SoloCook, *args) cmd.stubs(:check_chef_version) - cmd.stubs(:add_patches) + cmd.stubs(:run_portable_mkdir_p) cmd.stubs(:rsync) cmd.stubs(:stream_command).returns(SuccessfulResult.new) cmd From 7786cf2127add8b7752710803cded20e7affa29f Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Sat, 2 Mar 2013 22:31:49 -0500 Subject: [PATCH 08/33] Use explicit home dir in provisioning path. Fixes #212 Will probably break windows nodes where shell is cmd.exe-based --- lib/chef/knife/solo_cook.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index bda75c16..21faafe8 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -62,7 +62,8 @@ class SoloCook < Knife option :provisioning_path, :long => '--provisioning-path path', :description => 'Where to store kitchen data on the node', - :default => './chef-solo' + :default => '~/chef-solo' + # TODO ~ will likely break on cmd.exe based windows sessions def run time('Run') do From a302d79c530c002993f17192ec07494d816ab5c9 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Sat, 2 Mar 2013 22:32:06 -0500 Subject: [PATCH 09/33] Don't nest kitchen directories on the node --- lib/chef/knife/solo_cook.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index 21faafe8..5feb1586 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -97,9 +97,9 @@ def sync_kitchen upload(path, provisioning_path) end - upload(role_path, provisioning_path + '/roles') - upload(nodes_path, provisioning_path + '/nodes') - upload(data_bag_path, provisioning_path + '/data_bags') + upload(role_path + '/', provisioning_path + '/roles') + upload(nodes_path + '/', provisioning_path + '/nodes') + upload(data_bag_path + '/', provisioning_path + '/data_bags') upload(encrypted_data_bag_secret, provisioning_path + '/data_bag_key') if encrypted_data_bag_secret end From 224cdb6397c04d659e4ad4b3166c30c355fb58e7 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Sat, 2 Mar 2013 22:49:55 -0500 Subject: [PATCH 10/33] Include data bag key in default knife.rb Just don't try to transfer it if it's missing. --- lib/chef/knife/solo_cook.rb | 4 +++- lib/knife-solo/resources/knife.rb | 8 +------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index 5feb1586..27062f1b 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -100,7 +100,9 @@ def sync_kitchen upload(role_path + '/', provisioning_path + '/roles') upload(nodes_path + '/', provisioning_path + '/nodes') upload(data_bag_path + '/', provisioning_path + '/data_bags') - upload(encrypted_data_bag_secret, provisioning_path + '/data_bag_key') if encrypted_data_bag_secret + if File.exist?(encrypted_data_bag_secret) + upload(encrypted_data_bag_secret, provisioning_path + '/data_bag_key') + end end # TODO should watch for name collision here diff --git a/lib/knife-solo/resources/knife.rb b/lib/knife-solo/resources/knife.rb index 9f8ab182..4921205f 100644 --- a/lib/knife-solo/resources/knife.rb +++ b/lib/knife-solo/resources/knife.rb @@ -1,10 +1,4 @@ cookbook_path ["cookbooks", "site-cookbooks"] role_path "roles" data_bag_path "data_bags" - -# To use encryptd data bags first generate a secret: -# openssl rand -base64 512 | tr -d '\r\n' > data_bag_key -# Then uncomment the line below. - -# encrypted_data_bag_secret "data_bag_key" - +encrypted_data_bag_secret "data_bag_key" From c0de9c4347ed240e292f6704337277c6075d4093 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Sat, 2 Mar 2013 22:50:05 -0500 Subject: [PATCH 11/33] Don't clobber existing knife.rb --- lib/chef/knife/solo_init.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/chef/knife/solo_init.rb b/lib/chef/knife/solo_init.rb index 9628b197..2c6cc6a0 100644 --- a/lib/chef/knife/solo_init.rb +++ b/lib/chef/knife/solo_init.rb @@ -56,8 +56,11 @@ def create_kitchen def create_config ui.msg "Creating knife.rb in kitchen..." - mkdir File.join(@base, '.chef') - FileUtils.cp(KnifeSolo.resource('knife.rb'), File.join(@base, '.chef', 'knife.rb')) + mkdir_p File.join(@base, '.chef') + knife_rb = File.join(@base, '.chef', 'knife.rb') + unless File.exist?(knife_rb) + cp KnifeSolo.resource('knife.rb'), knife_rb + end end def librarian_init From 53c17743a7cdfec13a54607b20551c76208efc59 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Sat, 2 Mar 2013 22:55:45 -0500 Subject: [PATCH 12/33] Avoid checking data bag secret if option isn't set --- lib/chef/knife/solo_cook.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index 27062f1b..7509d8aa 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -100,7 +100,7 @@ def sync_kitchen upload(role_path + '/', provisioning_path + '/roles') upload(nodes_path + '/', provisioning_path + '/nodes') upload(data_bag_path + '/', provisioning_path + '/data_bags') - if File.exist?(encrypted_data_bag_secret) + if encrypted_data_bag_secret && File.exist?(encrypted_data_bag_secret) upload(encrypted_data_bag_secret, provisioning_path + '/data_bag_key') end end From 84785ef2d361e34e7710a2e4b928d6fe314d7f0f Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Sat, 2 Mar 2013 22:56:25 -0500 Subject: [PATCH 13/33] Pull out config object Since we rely on knife.rb and controlling the resulting paths, this config object seemed like more overhead than we need. --- Manifest.txt | 2 - lib/chef/knife/solo_clean.rb | 10 +++-- lib/knife-solo/config.rb | 64 -------------------------------- test/knife-solo/config_test.rb | 68 ---------------------------------- 4 files changed, 7 insertions(+), 137 deletions(-) delete mode 100644 lib/knife-solo/config.rb delete mode 100644 test/knife-solo/config_test.rb diff --git a/Manifest.txt b/Manifest.txt index 09ae5b0c..0eef83bf 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -17,7 +17,6 @@ lib/knife-solo/bootstraps/darwin.rb lib/knife-solo/bootstraps/freebsd.rb lib/knife-solo/bootstraps/linux.rb lib/knife-solo/bootstraps/sun_os.rb -lib/knife-solo/config.rb lib/knife-solo/deprecated_command.rb lib/knife-solo/gitignore.rb lib/knife-solo/info.rb @@ -47,7 +46,6 @@ test/integration/ubuntu10_04_test.rb test/integration/ubuntu12_04_bootstrap_test.rb test/integration/ubuntu12_04_test.rb test/integration_helper.rb -test/knife-solo/config_test.rb test/minitest/parallel.rb test/node_config_command_test.rb test/solo_bootstrap_test.rb diff --git a/lib/chef/knife/solo_clean.rb b/lib/chef/knife/solo_clean.rb index 5db89370..cec4ea39 100644 --- a/lib/chef/knife/solo_clean.rb +++ b/lib/chef/knife/solo_clean.rb @@ -1,7 +1,6 @@ require 'chef/knife' require 'knife-solo/ssh_command' -require 'knife-solo/config' class Chef class Knife @@ -10,10 +9,15 @@ class SoloClean < Knife banner "knife solo clean [USER@]HOSTNAME" + option :provisioning_path, + :long => '--provisioning-path path', + :description => 'Where to store kitchen data on the node', + :default => '~/chef-solo' + # TODO de-duplicate this option with solo cook + def run - @solo_config = KnifeSolo::Config.new validate! - run_command "rm -rf #{@solo_config.chef_path}" + run_command "rm -rf #{config[:provisioning_path]}" end def validate! diff --git a/lib/knife-solo/config.rb b/lib/knife-solo/config.rb deleted file mode 100644 index 7f81c9ff..00000000 --- a/lib/knife-solo/config.rb +++ /dev/null @@ -1,64 +0,0 @@ -require 'chef/config' -require 'knife-solo' -require 'erubis' - -module KnifeSolo - # Encapsulates some logic for checking and extracting - # path configuration from the structure of the - # current kitchen - class Config - def solo_path - Chef::Config.knife[:solo_path] - end - - def chef_path - solo_path || './chef-solo' - end - - def knife_solo_config - Chef::Config.knife[:solo] - end - - def process_path(path) - if path[0] == '.' - "base + #{path[1..-1].inspect}" - else - path.inspect - end - end - - def process_paths(paths) - return process_path(paths) unless paths.is_a? Array - "[" + paths.map { |path| process_path(path) }.join(',') + "]" - end - - def solo_rb - config = Chef::Config.knife[:solo] - path = config.delete(:path) || './chef-solo' - Erubis::Eruby.new(KnifeSolo.resource('solo.rb.erb').read).result(binding) - end - - def cookbook_path - if using_custom_solorb? - Chef::Config.from_file('solo.rb') - Array(Chef::Config.cookbook_path).first - else - chef_path + '/cookbooks' - end - end - - def patch_path - cookbook_path + "/chef_solo_patches/libraries" - end - - def using_custom_solorb? - File.exist?('solo.rb') - end - - def validate! - raise Error, "You have a solo.rb file, but knife[:solo_path] is not set. You probably need to delete solo.rb unless you've customized it. See https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.3.0 for more information." if using_custom_solorb? && solo_path.nil? - end - - class Error < StandardError; end - end -end diff --git a/test/knife-solo/config_test.rb b/test/knife-solo/config_test.rb deleted file mode 100644 index c0ba33c3..00000000 --- a/test/knife-solo/config_test.rb +++ /dev/null @@ -1,68 +0,0 @@ -require 'test_helper' -require 'knife-solo/config' - -class KnifeSoloConfigTest < TestCase - def setup - super - @config = KnifeSolo::Config.new - end - - def teardown - super - FileUtils.rm_f 'solo.rb' - end - - def test_can_generate_solorb_from_knife_configs - Chef::Config.knife[:solo] = { - :file_cache_path => "/custom/cache/path", - :data_bag_path => "/custom/data_bag/path", - :encrypted_data_bag_secret => "/custom/secret/path", - :role_path => "/custom/role/path", - :cookbook_path => [ "/custom/cookbook/path1", "/custom/cookbook/path2" ] - } - - write_file('solo.rb', @config.solo_rb) - Chef::Config.from_file('solo.rb') - - assert_equal "/custom/cache/path", Chef::Config.file_cache_path - assert_equal "/custom/data_bag/path", Chef::Config.data_bag_path - assert_equal "/custom/secret/path", Chef::Config.encrypted_data_bag_secret - assert_equal "/custom/role/path", Chef::Config.role_path - assert Chef::Config.cookbook_path.include?("/custom/cookbook/path1") && - Chef::Config.cookbook_path.include?("/custom/cookbook/path2") - end - - def test_expands_paths_relative_to_file - Chef::Config.knife[:solo] = { :data_bag_path => './data_bags', - :cookbook_path => ['./cookbooks'] } - write_file('solo.rb', @config.solo_rb) - Chef::Config.from_file('solo.rb') - assert_equal File.expand_path('../../../data_bags', __FILE__), - Chef::Config.data_bag_path - end - - def test_uses_cookbook_path_from_solo_rb_if_available - write_file('solo.rb', <<-RUBY) - knife[:solo_path] = "./custom" - cookbook_path ["./custom/path"] - RUBY - assert_equal "./custom/path", @config.cookbook_path - end - - def test_reads_chef_root_path_from_knife_config_or_defaults_to_home - Chef::Config.knife[:solo_path] = nil - assert_equal './chef-solo', @config.chef_path - Chef::Config.knife[:solo_path] = "/tmp/custom-chef-solo" - assert_equal "/tmp/custom-chef-solo", @config.chef_path - end - - def test_fails_validation_if_user_has_solo_rb_and_no_solo_path - Chef::Config.knife[:solo_path] = nil - write_file('solo.rb', <<-RUBY) - cookbook_path ["custom/path"] - RUBY - assert_raises KnifeSolo::Config::Error do - @config.validate! - end - end -end From 9874e48159530fe3101620cf64c10adcc781307e Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Sat, 2 Mar 2013 23:02:14 -0500 Subject: [PATCH 14/33] Fix path to search cookbook submodule --- .gitmodules | 4 +- Manifest.txt | 43 ++++++++++--------- .../chef-solo-search | 0 3 files changed, 24 insertions(+), 23 deletions(-) rename lib/knife-solo/resources/{patch_cookbook => patch_cookbooks}/chef-solo-search (100%) diff --git a/.gitmodules b/.gitmodules index 55f71f03..3f42dbfb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "lib/knife-solo/resources/patch_cookbook/chef-solo-search"] - path = lib/knife-solo/resources/patch_cookbook/chef-solo-search +[submodule "lib/knife-solo/resources/patch_cookbooks/chef-solo-search"] + path = lib/knife-solo/resources/patch_cookbooks/chef-solo-search url = https://github.com/edelight/chef-solo-search.git diff --git a/Manifest.txt b/Manifest.txt index 0eef83bf..d8c4c91e 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -23,6 +23,7 @@ lib/knife-solo/info.rb lib/knife-solo/node_config_command.rb lib/knife-solo/resources/knife.rb lib/knife-solo/resources/patch_cookbook/chef-solo-search +lib/knife-solo/resources/patch_cookbooks/chef-solo-search lib/knife-solo/resources/solo.rb.erb lib/knife-solo/ssh_command.rb lib/knife-solo/tools.rb @@ -71,24 +72,24 @@ test/support/ssh_config test/support/test_case.rb test/support/validation_helper.rb test/test_helper.rb -lib/knife-solo/resources/patch_cookbook/chef-solo-search/CHANGELOG -lib/knife-solo/resources/patch_cookbook/chef-solo-search/LICENSE -lib/knife-solo/resources/patch_cookbook/chef-solo-search/NOTICE -lib/knife-solo/resources/patch_cookbook/chef-solo-search/README.md -lib/knife-solo/resources/patch_cookbook/chef-solo-search/libraries/search.rb -lib/knife-solo/resources/patch_cookbook/chef-solo-search/libraries/search/overrides.rb -lib/knife-solo/resources/patch_cookbook/chef-solo-search/libraries/search/parser.rb -lib/knife-solo/resources/patch_cookbook/chef-solo-search/libraries/vendor/chef/solr_query/lucene.treetop -lib/knife-solo/resources/patch_cookbook/chef-solo-search/libraries/vendor/chef/solr_query/lucene_nodes.rb -lib/knife-solo/resources/patch_cookbook/chef-solo-search/libraries/vendor/chef/solr_query/query_transform.rb -lib/knife-solo/resources/patch_cookbook/chef-solo-search/metadata.rb -lib/knife-solo/resources/patch_cookbook/chef-solo-search/recipes/default.rb -lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/Gemfile -lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/data/data_bags/node/alpha.json -lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/data/data_bags/node/beta.json -lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/data/data_bags/users/jerry.json -lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/data/data_bags/users/lea.json -lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/data/data_bags/users/mike.json -lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/data/data_bags/users/tom.json -lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/test_data_bags.rb -lib/knife-solo/resources/patch_cookbook/chef-solo-search/tests/test_search.rb +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/CHANGELOG +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/LICENSE +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/NOTICE +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/README.md +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/libraries/search.rb +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/libraries/search/overrides.rb +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/libraries/search/parser.rb +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/libraries/vendor/chef/solr_query/lucene.treetop +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/libraries/vendor/chef/solr_query/lucene_nodes.rb +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/libraries/vendor/chef/solr_query/query_transform.rb +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/metadata.rb +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/recipes/default.rb +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/Gemfile +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/node/alpha.json +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/node/beta.json +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/users/jerry.json +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/users/lea.json +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/users/mike.json +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/users/tom.json +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_data_bags.rb +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/test_search.rb diff --git a/lib/knife-solo/resources/patch_cookbook/chef-solo-search b/lib/knife-solo/resources/patch_cookbooks/chef-solo-search similarity index 100% rename from lib/knife-solo/resources/patch_cookbook/chef-solo-search rename to lib/knife-solo/resources/patch_cookbooks/chef-solo-search From 366ba76c8c537e1e84e2496d1bdc92ae22fb0b41 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Sat, 2 Mar 2013 23:04:08 -0500 Subject: [PATCH 15/33] Manifest fix --- Manifest.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/Manifest.txt b/Manifest.txt index d8c4c91e..5e3d1315 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -22,7 +22,6 @@ lib/knife-solo/gitignore.rb lib/knife-solo/info.rb lib/knife-solo/node_config_command.rb lib/knife-solo/resources/knife.rb -lib/knife-solo/resources/patch_cookbook/chef-solo-search lib/knife-solo/resources/patch_cookbooks/chef-solo-search lib/knife-solo/resources/solo.rb.erb lib/knife-solo/ssh_command.rb From cb9bb4e20ad9a6d10642332cea65e40dd193744d Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Wed, 3 Apr 2013 23:08:35 -0300 Subject: [PATCH 16/33] Use `config_value` helper for `:provisioning_path` Allows setting the value in knife.rb with Chef 10, too. --- lib/chef/knife/solo_clean.rb | 15 ++++++++++++--- lib/chef/knife/solo_cook.rb | 7 +++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/chef/knife/solo_clean.rb b/lib/chef/knife/solo_clean.rb index cec4ea39..e4820324 100644 --- a/lib/chef/knife/solo_clean.rb +++ b/lib/chef/knife/solo_clean.rb @@ -7,23 +7,32 @@ class Knife class SoloClean < Knife include KnifeSolo::SshCommand + deps do + require 'knife-solo/tools' + KnifeSolo::SshCommand.load_deps + end + banner "knife solo clean [USER@]HOSTNAME" option :provisioning_path, :long => '--provisioning-path path', - :description => 'Where to store kitchen data on the node', - :default => '~/chef-solo' + :description => 'Where to store kitchen data on the node' # TODO de-duplicate this option with solo cook def run validate! - run_command "rm -rf #{config[:provisioning_path]}" + run_command "rm -rf #{provisioning_path}" end def validate! validate_ssh_options! @solo_config.validate! end + + def provisioning_path + # TODO de-duplicate this method with solo cook + KnifeSolo::Tools.config_value(config, :provisioning_path, '~/chef-solo') + end end end end diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index 02495e4f..db6fd701 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -58,9 +58,7 @@ class SoloCook < Knife option :provisioning_path, :long => '--provisioning-path path', - :description => 'Where to store kitchen data on the node', - :default => '~/chef-solo' - # TODO ~ will likely break on cmd.exe based windows sessions + :description => 'Where to store kitchen data on the node' def run time('Run') do @@ -84,7 +82,8 @@ def run end def provisioning_path - config[:provisioning_path] + # TODO ~ will likely break on cmd.exe based windows sessions + config_value(:provisioning_path, '~/chef-solo') end def sync_kitchen From 5c734a158705c38021a43a39bb98be60a5e43e87 Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Wed, 3 Apr 2013 23:21:52 -0300 Subject: [PATCH 17/33] Add optional mode option to `run_portable_mkdir_p` --- lib/knife-solo/ssh_command.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/knife-solo/ssh_command.rb b/lib/knife-solo/ssh_command.rb index 88002f7a..33567b7c 100644 --- a/lib/knife-solo/ssh_command.rb +++ b/lib/knife-solo/ssh_command.rb @@ -257,12 +257,13 @@ def run_command(command, options={}) # TODO: # - move this to a dedicated "portability" module? # - use ruby in all cases instead? - def run_portable_mkdir_p(folder) + def run_portable_mkdir_p(folder, mode = nil) if windows_node? # no mkdir -p on windows - fake it - run_command %Q{ruby -e "require 'fileutils'; FileUtils.mkdir_p('#{folder}')"} + run_command %Q{ruby -e "require 'fileutils'; FileUtils.mkdir_p('#{folder}', :mode => #{mode})"} else - run_command "mkdir -p #{folder}" + mode_option = (mode.nil? ? "" : "-m #{mode}") + run_command "mkdir -p #{mode_option} #{folder}" end end From d966abe50fc181d350b31bcacfcc1050646e66f2 Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Wed, 3 Apr 2013 23:25:26 -0300 Subject: [PATCH 18/33] Restrict permissions of the upload directory Set the provisioning_path dir mode so that it is not world-readable. Fixes #1. --- lib/chef/knife/solo_cook.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index db6fd701..69f04aa7 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -87,7 +87,7 @@ def provisioning_path end def sync_kitchen - run_portable_mkdir_p(provisioning_path) + run_portable_mkdir_p(provisioning_path, '0700') cookbook_paths.each do |path| upload(path, provisioning_path) From 611830489d31b2957a62782f01330f5b73e8e2c2 Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Thu, 4 Apr 2013 00:01:38 -0300 Subject: [PATCH 19/33] Ensure unique names for cookbook directories Avoid possible collisions between user cookbook directories, our patch cookbooks and future Berkshelf integration. --- lib/chef/knife/solo_cook.rb | 5 ++--- lib/knife-solo/resources/solo.rb.erb | 12 +++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index 69f04aa7..95c31285 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -89,8 +89,8 @@ def provisioning_path def sync_kitchen run_portable_mkdir_p(provisioning_path, '0700') - cookbook_paths.each do |path| - upload(path, provisioning_path) + cookbook_paths.each_with_index do |path, i| + upload(path + '/', provisioning_path + "/cookbooks-#{i + 1}") end upload(role_path + '/', provisioning_path + '/roles') @@ -101,7 +101,6 @@ def sync_kitchen end end - # TODO should watch for name collision here def cookbook_paths Chef::Config.cookbook_path + [KnifeSolo.resource('patch_cookbooks')] end diff --git a/lib/knife-solo/resources/solo.rb.erb b/lib/knife-solo/resources/solo.rb.erb index 59e3d9d9..ed1606df 100644 --- a/lib/knife-solo/resources/solo.rb.erb +++ b/lib/knife-solo/resources/solo.rb.erb @@ -1,8 +1,10 @@ base = File.expand_path('..', __FILE__) -role_path base + '/roles' -data_bag_path base + '/data_bags' -encrypted_data_bag_secret base + '/data_bag_key' - -cookbook_path [ <%= cookbook_paths.map { |p| "base + '/' + " + File.basename(p).inspect }.join(', ') %> ] +role_path File.join(base, 'roles') +data_bag_path File.join(base, 'data_bags') +encrypted_data_bag_secret File.join(base, 'data_bag_key') +cookbook_path [] +<% cookbook_paths.each_with_index do |path, i| -%> +cookbook_path << File.join(base, 'cookbooks-<%= i+1 %>') # <%= path %> +<% end -%> From 20b3c140ffd02c8352c6e49fed1613bf6bf65396 Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Thu, 4 Apr 2013 00:09:00 -0300 Subject: [PATCH 20/33] Lazy load dependencies --- lib/chef/knife/solo_cook.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index 95c31285..b3a0b4c3 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -5,10 +5,6 @@ require 'knife-solo/node_config_command' require 'knife-solo/tools' -require 'tempfile' -require 'erubis' -require 'chef/config' - class Chef class Knife # Approach ported from spatula (https://github.com/trotter/spatula) @@ -22,7 +18,9 @@ class SoloCook < Knife deps do require 'chef/cookbook/chefignore' + require 'erubis' require 'pathname' + require 'tempfile' KnifeSolo::SshCommand.load_deps KnifeSolo::NodeConfigCommand.load_deps end From e8ddd2761e258bf452aa804040924d3f976212c0 Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Thu, 4 Apr 2013 00:42:35 -0300 Subject: [PATCH 21/33] Ensure patch_cookbooks path is a string --- lib/chef/knife/solo_cook.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index b3a0b4c3..d3aaea49 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -100,7 +100,7 @@ def sync_kitchen end def cookbook_paths - Chef::Config.cookbook_path + [KnifeSolo.resource('patch_cookbooks')] + Chef::Config.cookbook_path + [KnifeSolo.resource('patch_cookbooks').to_s] end def nodes_path From f3d61efce2869a4bc07e5a1cdfb9b871d8070cb4 Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Thu, 4 Apr 2013 00:43:03 -0300 Subject: [PATCH 22/33] Check that uploaded paths are defined and exist --- lib/chef/knife/solo_cook.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index d3aaea49..ddbfb52a 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -88,15 +88,13 @@ def sync_kitchen run_portable_mkdir_p(provisioning_path, '0700') cookbook_paths.each_with_index do |path, i| - upload(path + '/', provisioning_path + "/cookbooks-#{i + 1}") + upload_to_provision_path(path, "/cookbooks-#{i + 1}") end - upload(role_path + '/', provisioning_path + '/roles') - upload(nodes_path + '/', provisioning_path + '/nodes') - upload(data_bag_path + '/', provisioning_path + '/data_bags') - if encrypted_data_bag_secret && File.exist?(encrypted_data_bag_secret) - upload(encrypted_data_bag_secret, provisioning_path + '/data_bag_key') - end + upload_to_provision_path(role_path, 'roles') + upload_to_provision_path(nodes_path, 'nodes') + upload_to_provision_path(data_bag_path, 'data_bags') + upload_to_provision_path(encrypted_data_bag_secret, 'data_bag_key') end def cookbook_paths @@ -196,6 +194,12 @@ def upload(src, dest) rsync(src, dest) end + def upload_to_provision_path(src, dest) + if src && File.exist?(src) + upload("#{src}/", File.join(provisioning_path, dest)) + end + end + # TODO probably can get Net::SSH to do this directly def write(content, dest) file = Tempfile.new(File.basename(dest)) From 19a44c384644238cbb06e6e094fa94600f7692c9 Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Thu, 4 Apr 2013 00:50:38 -0300 Subject: [PATCH 23/33] Add a log message when syncing the kitchen --- lib/chef/knife/solo_cook.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index ddbfb52a..831a0e1f 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -85,6 +85,7 @@ def provisioning_path end def sync_kitchen + ui.msg "Uploading the kitchen..." run_portable_mkdir_p(provisioning_path, '0700') cookbook_paths.each_with_index do |path, i| From 9f722c85fe7ce43a2148b601ce1187e67ae846d9 Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Thu, 4 Apr 2013 19:27:45 -0300 Subject: [PATCH 24/33] Upgrade chef-solo-search to v0.4.0 --- Manifest.txt | 2 ++ lib/knife-solo/resources/patch_cookbooks/chef-solo-search | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Manifest.txt b/Manifest.txt index 7ac66f13..12b0c6b3 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -75,6 +75,7 @@ test/support/test_case.rb test/support/validation_helper.rb test/test_helper.rb test/tools_test.rb +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/.travis.yml lib/knife-solo/resources/patch_cookbooks/chef-solo-search/CHANGELOG lib/knife-solo/resources/patch_cookbooks/chef-solo-search/LICENSE lib/knife-solo/resources/patch_cookbooks/chef-solo-search/NOTICE @@ -90,6 +91,7 @@ lib/knife-solo/resources/patch_cookbooks/chef-solo-search/recipes/default.rb lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/Gemfile lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/node/alpha.json lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/node/beta.json +lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/node/without_json_class.json lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/users/jerry.json lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/users/lea.json lib/knife-solo/resources/patch_cookbooks/chef-solo-search/tests/data/data_bags/users/mike.json diff --git a/lib/knife-solo/resources/patch_cookbooks/chef-solo-search b/lib/knife-solo/resources/patch_cookbooks/chef-solo-search index da3cdbdf..5ba022d0 160000 --- a/lib/knife-solo/resources/patch_cookbooks/chef-solo-search +++ b/lib/knife-solo/resources/patch_cookbooks/chef-solo-search @@ -1 +1 @@ -Subproject commit da3cdbdf3547bc2d9ffb71e2bb58a10723ab6e93 +Subproject commit 5ba022d02c51cafc7b5323c1209fbb7936e4f60b From c54e8e4ffbd9ced2fbfdf727fba232593e79b3ee Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Thu, 4 Apr 2013 19:27:57 -0300 Subject: [PATCH 25/33] Remove forgotten solo_config reference --- lib/chef/knife/solo_clean.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/chef/knife/solo_clean.rb b/lib/chef/knife/solo_clean.rb index e4820324..4a3de38e 100644 --- a/lib/chef/knife/solo_clean.rb +++ b/lib/chef/knife/solo_clean.rb @@ -26,7 +26,6 @@ def run def validate! validate_ssh_options! - @solo_config.validate! end def provisioning_path From 55eacea9c778a3da98c2404062ffe8f2de26e1bd Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Thu, 4 Apr 2013 23:13:30 -0300 Subject: [PATCH 26/33] Warn if solo.rb exists --- lib/chef/knife/solo_cook.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index 831a0e1f..a2d0bd08 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -79,6 +79,15 @@ def run end end + def validate! + validate_ssh_options! + + if File.exist? 'solo.rb' + ui.warn "solo.rb found, but since knife-solo v0.3.0 it is not used any more" + ui.warn "Please read the upgrade instructions: https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.3.0" + end + end + def provisioning_path # TODO ~ will likely break on cmd.exe based windows sessions config_value(:provisioning_path, '~/chef-solo') @@ -111,10 +120,6 @@ def nodes_path :data_bag_path, :encrypted_data_bag_secret - def validate! - validate_ssh_options! - end - def chefignore @chefignore ||= ::Chef::Cookbook::Chefignore.new("./") end From 6ab97e96ebd19eedbdde497d8068307e56348fcc Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Thu, 4 Apr 2013 23:37:15 -0300 Subject: [PATCH 27/33] Ensure cookbook_path is an Array It is common to specify it as a string if there is only one cookbook directory. --- lib/chef/knife/solo_cook.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index a2d0bd08..dd85aa57 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -108,7 +108,7 @@ def sync_kitchen end def cookbook_paths - Chef::Config.cookbook_path + [KnifeSolo.resource('patch_cookbooks').to_s] + Array(Chef::Config.cookbook_path) + [KnifeSolo.resource('patch_cookbooks').to_s] end def nodes_path From 47908c3ab20fe0159fae612548cdeb4f2c200957 Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Thu, 4 Apr 2013 23:41:59 -0300 Subject: [PATCH 28/33] Comment out encrypted_data_bag_secret from the generated knife.rb --- lib/knife-solo/resources/knife.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/knife-solo/resources/knife.rb b/lib/knife-solo/resources/knife.rb index 4921205f..a22053b3 100644 --- a/lib/knife-solo/resources/knife.rb +++ b/lib/knife-solo/resources/knife.rb @@ -1,4 +1,4 @@ cookbook_path ["cookbooks", "site-cookbooks"] role_path "roles" data_bag_path "data_bags" -encrypted_data_bag_secret "data_bag_key" +#encrypted_data_bag_secret "data_bag_key" From 2952e7f9f8cc84b294645a4286d0c8256c7d8d63 Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Fri, 5 Apr 2013 00:12:19 -0300 Subject: [PATCH 29/33] Warn if the local paths are not found Chef/Knife configuration for cookbook_path etc. defaults to system paths. So unless the user has configured her knife.rb, the paths don't normally exist. --- lib/chef/knife/solo_cook.rb | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index dd85aa57..e9c4dc89 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -98,28 +98,22 @@ def sync_kitchen run_portable_mkdir_p(provisioning_path, '0700') cookbook_paths.each_with_index do |path, i| - upload_to_provision_path(path, "/cookbooks-#{i + 1}") + upload_to_provision_path(path, "/cookbooks-#{i + 1}", 'cookbook_path') end - - upload_to_provision_path(role_path, 'roles') upload_to_provision_path(nodes_path, 'nodes') - upload_to_provision_path(data_bag_path, 'data_bags') - upload_to_provision_path(encrypted_data_bag_secret, 'data_bag_key') + upload_to_provision_path(:role_path, 'roles') + upload_to_provision_path(:data_bag_path, 'data_bags') + upload_to_provision_path(:encrypted_data_bag_secret, 'data_bag_key') end def cookbook_paths - Array(Chef::Config.cookbook_path) + [KnifeSolo.resource('patch_cookbooks').to_s] + Array(Chef::Config[:cookbook_path]) + [KnifeSolo.resource('patch_cookbooks').to_s] end def nodes_path 'nodes' end - def_delegators 'Chef::Config', - :role_path, - :data_bag_path, - :encrypted_data_bag_secret - def chefignore @chefignore ||= ::Chef::Cookbook::Chefignore.new("./") end @@ -200,8 +194,17 @@ def upload(src, dest) rsync(src, dest) end - def upload_to_provision_path(src, dest) - if src && File.exist?(src) + def upload_to_provision_path(src, dest, key_name = 'path') + if src.is_a? Symbol + key_name = src.to_s + src = Chef::Config[src] + end + + if src.nil? + Chef::Log.debug "'#{key_name}' not set" + elsif !File.exist?(src) + ui.warn "Local #{key_name} '#{src}' does not exist" + else upload("#{src}/", File.join(provisioning_path, dest)) end end From c3a24682bc134937de99dab482a57faf8770139e Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Fri, 5 Apr 2013 00:44:01 -0300 Subject: [PATCH 30/33] Update the changelog --- CHANGELOG.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9711c6be..7b3ac15c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,12 @@ # 0.3.0 / _In progress_ +**NOTE**: This release includes breaking changes. See [upgrade instructions](https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.3.0) for more information. + ## Changes and new features -* Moved root path configuration into `knife[:solo_path]` and use $HOME/chef-solo by default ([197]) +* [BREAKING] Generate solo.rb based on knife.rb settings ([199]) +* [BREAKING] Set root path with `--provisioning-path` or `knife[:provisioning_path]` and use ~/chef-solo by default ([1], [86], [125], [128], [177], [197]) +* Read protect the provision directory from the world ([1]) * `--prerelease` option to allow pre-release versions of chef omnibus or rubygem to be installed ([205]) * Prepare/bootstrap now installs the same version of Chef that the workstation is running ([186]) * Remove hard dependency on Librarian-Chef ([211]) @@ -28,9 +32,15 @@ * [Naoya Ito][naoya] * [David Radcliffe][dwradcliffe] +[1]: https://github.com/matschaffer/knife-solo/issues/1 +[86]: https://github.com/matschaffer/knife-solo/issues/86 +[125]: https://github.com/matschaffer/knife-solo/issues/125 +[128]: https://github.com/matschaffer/knife-solo/issues/128 +[177]: https://github.com/matschaffer/knife-solo/issues/177 [185]: https://github.com/matschaffer/knife-solo/issues/185 [186]: https://github.com/matschaffer/knife-solo/issues/186 [197]: https://github.com/matschaffer/knife-solo/issues/197 +[199]: https://github.com/matschaffer/knife-solo/issues/199 [200]: https://github.com/matschaffer/knife-solo/issues/200 [204]: https://github.com/matschaffer/knife-solo/issues/204 [205]: https://github.com/matschaffer/knife-solo/issues/205 @@ -62,7 +72,6 @@ * Drop support for Debian 5.0 Lenny (#172) * Integration tests for Debian 6 and 7 (74c6ed1 - f299a6) * Travis tests for both Chef 10 and 11 (#183) -* Remove solo.rb and transfer cookbooks to user-owned path (#1, #86, #125, #128, #177). See https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.2.0 ## Fixes From 147ad533fce65f6153ae4a314ac309bc30b54e0d Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Fri, 5 Apr 2013 00:53:56 -0300 Subject: [PATCH 31/33] Update the readme --- README.rdoc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.rdoc b/README.rdoc index 368567fa..895c9295 100644 --- a/README.rdoc +++ b/README.rdoc @@ -35,12 +35,13 @@ The init command simply takes a name of the directory to store the kitchen struc Currently the directory structure looks like this, but could change as development continues. mychefrepo/ + ├── .chef + │ └── knife.rb ├── cookbooks ├── data_bags ├── nodes ├── roles - ├── site-cookbooks - └── solo.rb + └── site-cookbooks === Prepare command @@ -71,7 +72,7 @@ The cook command uploads the current kitchen to the server and runs chef-solo on This uploads all of your cookbooks in addition to a patch that allows you to use data_bags in a read-only fashion from the +data_bags+ folder. -This also supports encrypted data bags. To use them, place your key in +data_bag_key+ in the root of your kitchen (or if you move it make sure to update +solo.rb+ to reflect the new path). +This also supports encrypted data bags. To use them, set the path to your key with +encrypted_data_bag_secret+ in .chef/knife.rb. The knife command for creating encrypted data bags doesn't work well without a Chef server, so use {this gist}[https://gist.github.com/2896172] as an example on how to create encrypted data bag items on your local file system. @@ -99,9 +100,9 @@ The clean command removes an uploaded kitchen completely from the target host. T The cook command will work on Windows node if you meet the following howto: -==== Init then tweak +==== Init as normally -- run knife solo init then edit solo.rb to use Windows path-naming (see https://gist.github.com/1773854) +- run knife solo init ==== Prepare the node manually From 471f54cf72793297170de15cbb87762bc172b618 Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Fri, 5 Apr 2013 16:45:24 -0300 Subject: [PATCH 32/33] Add trailing slash to only directories when rsyncin --- lib/chef/knife/solo_cook.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/chef/knife/solo_cook.rb b/lib/chef/knife/solo_cook.rb index e9c4dc89..912480c0 100644 --- a/lib/chef/knife/solo_cook.rb +++ b/lib/chef/knife/solo_cook.rb @@ -205,7 +205,8 @@ def upload_to_provision_path(src, dest, key_name = 'path') elsif !File.exist?(src) ui.warn "Local #{key_name} '#{src}' does not exist" else - upload("#{src}/", File.join(provisioning_path, dest)) + src << '/' if File.directory? src + upload(src, File.join(provisioning_path, dest)) end end From ae904d2be34a843b3b8681e83af2e3f152623d4f Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Fri, 5 Apr 2013 18:42:04 -0300 Subject: [PATCH 33/33] Configure data_bag key on integration tests --- test/integration/cases/encrypted_data_bag.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/integration/cases/encrypted_data_bag.rb b/test/integration/cases/encrypted_data_bag.rb index 0056b603..7ec5311a 100644 --- a/test/integration/cases/encrypted_data_bag.rb +++ b/test/integration/cases/encrypted_data_bag.rb @@ -5,6 +5,9 @@ def setup super FileUtils.cp $base_dir.join('support', 'data_bag_key'), 'data_bag_key' FileUtils.cp_r $base_dir.join('support', 'secret_cookbook'), 'cookbooks/secret_cookbook' + File.open('.chef/knife.rb', 'a') do |f| + f.puts 'encrypted_data_bag_secret "data_bag_key"' + end @password = "essential particles busy loud" create_data_bag end