...
 
Commits (4)
...@@ -75,20 +75,20 @@ module ChefConfig ...@@ -75,20 +75,20 @@ module ChefConfig
end end
# On *nix, /etc/chef # On *nix, /etc/chef
def self.etc_chef_dir def self.etc_chef_dir(is_windows = ChefUtils.windows?)
path = ChefUtils.windows? ? c_chef_dir : PathHelper.join("/etc", ChefConfig::Dist::DIR_SUFFIX) path = is_windows ? c_chef_dir : PathHelper.join("/etc", ChefConfig::Dist::DIR_SUFFIX)
PathHelper.cleanpath(path) PathHelper.cleanpath(path)
end end
# On *nix, /var/chef # On *nix, /var/chef
def self.var_chef_dir def self.var_chef_dir(is_windows = ChefUtils.windows?)
path = ChefUtils.windows? ? c_chef_dir : PathHelper.join("/var", ChefConfig::Dist::DIR_SUFFIX) path = is_windows ? c_chef_dir : PathHelper.join("/var", ChefConfig::Dist::DIR_SUFFIX)
PathHelper.cleanpath(path) PathHelper.cleanpath(path)
end end
# On *nix, the root of /var/, used to test if we can create and write in /var/chef # On *nix, the root of /var/, used to test if we can create and write in /var/chef
def self.var_root_dir def self.var_root_dir(is_windows = ChefUtils.windows?)
path = ChefUtils.windows? ? c_chef_dir : "/var" path = is_windows ? c_chef_dir : "/var"
PathHelper.cleanpath(path) PathHelper.cleanpath(path)
end end
...@@ -99,6 +99,12 @@ module ChefConfig ...@@ -99,6 +99,12 @@ module ChefConfig
PathHelper.cleanpath(path) PathHelper.cleanpath(path)
end end
def self.c_opscode_dir
drive = windows_installation_drive || "C:"
path = PathHelper.join(drive, ChefConfig::Dist::LEGACY_CONF_DIR, ChefConfig::Dist::DIR_SUFFIX)
PathHelper.cleanpath(path)
end
# the drive where Chef is installed on a windows host. This is determined # the drive where Chef is installed on a windows host. This is determined
# either by the drive containing the current file or by the SYSTEMDRIVE ENV # either by the drive containing the current file or by the SYSTEMDRIVE ENV
# variable # variable
......
...@@ -15,5 +15,9 @@ module ChefConfig ...@@ -15,5 +15,9 @@ module ChefConfig
# The user's configuration directory # The user's configuration directory
USER_CONF_DIR = ".chef".freeze USER_CONF_DIR = ".chef".freeze
# The legacy conf folder: C:/opscode/chef. Specifically the "opscode" part
# DIR_SUFFIX is appended to it in code where relevant
LEGACY_CONF_DIR = "opscode".freeze
end end
end end
...@@ -185,50 +185,50 @@ if test "x$tmp_dir" != "x"; then ...@@ -185,50 +185,50 @@ if test "x$tmp_dir" != "x"; then
rm -r "$tmp_dir" rm -r "$tmp_dir"
fi fi
mkdir -p /etc/chef mkdir -p <%= ChefConfig::Config.etc_chef_dir(false) %>
<% if client_pem -%> <% if client_pem -%>
(umask 077 && (cat > /etc/chef/client.pem <<'EOP' (umask 077 && (cat > <%= ChefConfig::Config.etc_chef_dir(false) %>/client.pem <<'EOP'
<%= ::File.read(::File.expand_path(client_pem)) %> <%= ::File.read(::File.expand_path(client_pem)) %>
EOP EOP
)) || exit 1 )) || exit 1
<% end -%> <% end -%>
<% if validation_key -%> <% if validation_key -%>
(umask 077 && (cat > /etc/chef/validation.pem <<'EOP' (umask 077 && (cat > <%= ChefConfig::Config.etc_chef_dir(false) %>/validation.pem <<'EOP'
<%= validation_key %> <%= validation_key %>
EOP EOP
)) || exit 1 )) || exit 1
<% end -%> <% end -%>
<% if encrypted_data_bag_secret -%> <% if encrypted_data_bag_secret -%>
(umask 077 && (cat > /etc/chef/encrypted_data_bag_secret <<'EOP' (umask 077 && (cat > <%= ChefConfig::Config.etc_chef_dir(false) %>/encrypted_data_bag_secret <<'EOP'
<%= encrypted_data_bag_secret %> <%= encrypted_data_bag_secret %>
EOP EOP
)) || exit 1 )) || exit 1
<% end -%> <% end -%>
<% unless trusted_certs.empty? -%> <% unless trusted_certs.empty? -%>
mkdir -p /etc/chef/trusted_certs mkdir -p <%= ChefConfig::Config.etc_chef_dir(false) %>/trusted_certs
<%= trusted_certs %> <%= trusted_certs %>
<% end -%> <% end -%>
<%# Generate Ohai Hints -%> <%# Generate Ohai Hints -%>
<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%> <% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
mkdir -p /etc/chef/ohai/hints mkdir -p <%= ChefConfig::Config.etc_chef_dir(false) %>/ohai/hints
<% @chef_config[:knife][:hints].each do |name, hash| -%> <% @chef_config[:knife][:hints].each do |name, hash| -%>
cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' cat > <%= ChefConfig::Config.etc_chef_dir(false) %>/ohai/hints/<%= name %>.json <<'EOP'
<%= Chef::JSONCompat.to_json(hash) %> <%= Chef::JSONCompat.to_json(hash) %>
EOP EOP
<% end -%> <% end -%>
<% end -%> <% end -%>
cat > /etc/chef/client.rb <<'EOP' cat > <%= ChefConfig::Config.etc_chef_dir(false) %>/client.rb <<'EOP'
<%= config_content %> <%= config_content %>
EOP EOP
cat > /etc/chef/first-boot.json <<'EOP' cat > <%= ChefConfig::Config.etc_chef_dir(false) %>/first-boot.json <<'EOP'
<%= Chef::JSONCompat.to_json(first_boot) %> <%= Chef::JSONCompat.to_json(first_boot) %>
EOP EOP
......
...@@ -120,11 +120,11 @@ If !ERRORLEVEL!==0 ( ...@@ -120,11 +120,11 @@ If !ERRORLEVEL!==0 (
) )
:install :install
@rem If user has provided the custom installation command for <%= Chef::Dist::CLIENT %> then execute it @rem If user has provided the custom installation command, execute it
<% if @chef_config[:knife][:bootstrap_install_command] %> <% if @chef_config[:knife][:bootstrap_install_command] %>
<%= @chef_config[:knife][:bootstrap_install_command] %> <%= @chef_config[:knife][:bootstrap_install_command] %>
<% else %> <% else %>
@rem Install Chef using <%= Chef::Dist::CLIENT %> MSI installer @rem Install Chef using the MSI installer
@set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>" @set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
@set "CHEF_CLIENT_MSI_LOG_PATH=%TEMP%\<%= Chef::Dist::CLIENT %>-msi%RANDOM%.log" @set "CHEF_CLIENT_MSI_LOG_PATH=%TEMP%\<%= Chef::Dist::CLIENT %>-msi%RANDOM%.log"
......
...@@ -59,9 +59,9 @@ class Chef ...@@ -59,9 +59,9 @@ class Chef
client_rb = <<~CONFIG client_rb = <<~CONFIG
chef_server_url "#{@chef_config[:chef_server_url]}" chef_server_url "#{@chef_config[:chef_server_url]}"
validation_client_name "#{@chef_config[:validation_client_name]}" validation_client_name "#{@chef_config[:validation_client_name]}"
file_cache_path "c:/chef/cache" file_cache_path "#{ChefConfig::Config.var_chef_dir(true)}/cache"
file_backup_path "c:/chef/backup" file_backup_path "#{ChefConfig::Config.var_chef_dir(true)}/backup"
cache_options ({:path => "c:/chef/cache/checksums", :skip_expires => true}) cache_options ({:path => "#{ChefConfig::Config.etc_chef_dir(true)}/cache/checksums", :skip_expires => true})
CONFIG CONFIG
unless @chef_config[:chef_license].nil? unless @chef_config[:chef_license].nil?
...@@ -124,11 +124,11 @@ class Chef ...@@ -124,11 +124,11 @@ class Chef
end end
if @config[:secret] if @config[:secret]
client_rb << %Q{encrypted_data_bag_secret "c:/chef/encrypted_data_bag_secret"\n} client_rb << %Q{encrypted_data_bag_secret "#{ChefConfig::Config.etc_chef_dir(true)}/encrypted_data_bag_secret"\n}
end end
unless trusted_certs_script.empty? unless trusted_certs_script.empty?
client_rb << %Q{trusted_certs_dir "c:/chef/trusted_certs"\n} client_rb << %Q{trusted_certs_dir "#{ChefConfig::Config.etc_chef_dir(true)}/trusted_certs"\n}
end end
if Chef::Config[:fips] if Chef::Config[:fips]
...@@ -158,8 +158,8 @@ class Chef ...@@ -158,8 +158,8 @@ class Chef
def start_chef def start_chef
bootstrap_environment_option = bootstrap_environment.nil? ? "" : " -E #{bootstrap_environment}" bootstrap_environment_option = bootstrap_environment.nil? ? "" : " -E #{bootstrap_environment}"
start_chef = "SET \"PATH=%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\;C:\\ruby\\bin;C:\\opscode\\chef\\bin;C:\\opscode\\chef\\embedded\\bin\;%PATH%\"\n" start_chef = "SET \"PATH=%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\;C:\\ruby\\bin;#{ChefConfig::Config.c_opscode_dir}\\#{ChefConfig::Dist::DIR_SUFFIX}\\bin;#{ChefConfig::Config.c_opscode_dir}\\#{ChefConfig::Dist::DIR_SUFFIX}\\embedded\\bin\;%PATH%\"\n"
start_chef << "chef-client -c c:/chef/client.rb -j c:/chef/first-boot.json#{bootstrap_environment_option}\n" start_chef << "chef-client -c #{ChefConfig::Config.etc_chef_dir(true)}/client.rb -j #{ChefConfig::Config.etc_chef_dir(true)}/first-boot.json#{bootstrap_environment_option}\n"
end end
def win_wget def win_wget
...@@ -260,7 +260,7 @@ class Chef ...@@ -260,7 +260,7 @@ class Chef
end end
def bootstrap_directory def bootstrap_directory
"C:\\chef" ChefConfig::Config.etc_chef_dir(true)
end end
def local_download_path def local_download_path
......
...@@ -164,9 +164,9 @@ describe Chef::Knife::Core::WindowsBootstrapContext do ...@@ -164,9 +164,9 @@ describe Chef::Knife::Core::WindowsBootstrapContext do
expected = <<~EXPECTED expected = <<~EXPECTED
echo.chef_server_url "http://chef.example.com:4444" echo.chef_server_url "http://chef.example.com:4444"
echo.validation_client_name "chef-validator-testing" echo.validation_client_name "chef-validator-testing"
echo.file_cache_path "c:/chef/cache" echo.file_cache_path "C:/chef/cache"
echo.file_backup_path "c:/chef/backup" echo.file_backup_path "C:/chef/backup"
echo.cache_options ^({:path =^> "c:/chef/cache/checksums", :skip_expires =^> true}^) echo.cache_options ^({:path =^> "C:/chef/cache/checksums", :skip_expires =^> true}^)
echo.# Using default node name ^(fqdn^) echo.# Using default node name ^(fqdn^)
echo.log_level :info echo.log_level :info
echo.log_location STDOUT echo.log_location STDOUT
......