summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-05-20 10:57:05 -0700
committerGitHub <noreply@github.com>2020-05-20 10:57:05 -0700
commita225d93086983994addea463ee85d637de4e9246 (patch)
tree1372f682aa71c9eac3736805727fd42b3f071019
parent3536688af38f6ae1e447fa8d03bdaee8c4ec4a3a (diff)
parent5c3fcc525332a45e80fc3cc5d550ae7866eb9364 (diff)
downloadchef-a225d93086983994addea463ee85d637de4e9246.tar.gz
Merge pull request #9889 from chef/btm/fix-cannot-find-the-batch-label
Fix bootstrapping windows from linux
-rw-r--r--lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb4
-rw-r--r--lib/chef/knife/core/windows_bootstrap_context.rb17
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb b/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb
index 0b444e718c..9699c09b0e 100644
--- a/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb
+++ b/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb
@@ -202,10 +202,12 @@ If !ERRORLEVEL!==0 (
) else (
@echo Installation completed successfully
del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
- )
+ )
<% end %>
+@rem This line is required to separate the key_create label from the "block boundary"
+@rem Removing these lines will cause the error "The system cannot find the batch label specified - key_create"
:key_create
@endlocal
diff --git a/lib/chef/knife/core/windows_bootstrap_context.rb b/lib/chef/knife/core/windows_bootstrap_context.rb
index d2b9bc5636..f0b9021843 100644
--- a/lib/chef/knife/core/windows_bootstrap_context.rb
+++ b/lib/chef/knife/core/windows_bootstrap_context.rb
@@ -41,6 +41,21 @@ class Chef
super(config, run_list, chef_config, secret)
end
+ # This is a duplicate of ChefConfig::PathHelper.cleanpath, however
+ # this presumes Windows so we can avoid changing the method definitions
+ # across Chef, ChefConfig, and ChefUtils for the circumstance where
+ # the methods are being run for a system other than the one Ruby is
+ # executing on.
+ #
+ # We only need to cleanpath the paths that we are passing to cmd.exe,
+ # anything written to a configuration file or passed as an argument
+ # will be interpreted by ruby later and do the right thing.
+ def cleanpath(path)
+ path = Pathname.new(path).cleanpath.to_s
+ path = path.gsub(File::SEPARATOR, '\\')
+ path
+ end
+
def validation_key
if File.exist?(File.expand_path(chef_config[:validation_key]))
IO.read(File.expand_path(chef_config[:validation_key]))
@@ -262,7 +277,7 @@ class Chef
end
def bootstrap_directory
- ChefConfig::Config.etc_chef_dir(true)
+ cleanpath(ChefConfig::Config.etc_chef_dir(true))
end
def local_download_path