summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Chamberland <chamberland.marc@gmail.com>2020-01-29 21:25:48 -0500
committerMarc Chamberland <chamberland.marc@gmail.com>2020-02-26 19:02:08 -0500
commit2be4e0e3c52151c90767571adb1f834fb746f821 (patch)
tree818703aed3664b18dbf89bb72c004f326324b8b9
parenteaa308a34c24aef7b374c16098fca360db449ea8 (diff)
downloadchef-2be4e0e3c52151c90767571adb1f834fb746f821.tar.gz
Pass distro and platform specific paths into bootstrap templates
Signed-off-by: Marc Chamberland <chamberland.marc@gmail.com>
-rw-r--r--chef-config/lib/chef-config/config.rb13
-rw-r--r--lib/chef/knife/bootstrap/templates/chef-full.erb18
-rw-r--r--lib/chef/knife/core/windows_bootstrap_context.rb16
3 files changed, 24 insertions, 23 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb
index 484e1ea2f6..6e0da21e51 100644
--- a/chef-config/lib/chef-config/config.rb
+++ b/chef-config/lib/chef-config/config.rb
@@ -75,20 +75,21 @@ module ChefConfig
end
# On *nix, /etc/chef
- def self.etc_chef_dir
- path = ChefUtils.windows? ? c_chef_dir : PathHelper.join("/etc", ChefConfig::Dist::DIR_SUFFIX)
+
+ def self.etc_chef_dir(is_windows = ChefUtils.windows?)
+ path = is_windows ? c_chef_dir : PathHelper.join("/etc", ChefConfig::Dist::DIR_SUFFIX)
PathHelper.cleanpath(path)
end
# On *nix, /var/chef
- def self.var_chef_dir
- path = ChefUtils.windows? ? c_chef_dir : PathHelper.join("/var", ChefConfig::Dist::DIR_SUFFIX)
+ def self.var_chef_dir(is_windows = ChefUtils.windows?)
+ path = is_windows ? c_chef_dir : PathHelper.join("/var", ChefConfig::Dist::DIR_SUFFIX)
PathHelper.cleanpath(path)
end
# On *nix, the root of /var/, used to test if we can create and write in /var/chef
- def self.var_root_dir
- path = ChefUtils.windows? ? c_chef_dir : "/var"
+ def self.var_root_dir(is_windows = ChefUtils.windows?)
+ path = is_windows ? c_chef_dir : "/var"
PathHelper.cleanpath(path)
end
diff --git a/lib/chef/knife/bootstrap/templates/chef-full.erb b/lib/chef/knife/bootstrap/templates/chef-full.erb
index 7743142332..263203ca76 100644
--- a/lib/chef/knife/bootstrap/templates/chef-full.erb
+++ b/lib/chef/knife/bootstrap/templates/chef-full.erb
@@ -185,50 +185,50 @@ if test "x$tmp_dir" != "x"; then
rm -r "$tmp_dir"
fi
-mkdir -p /etc/chef
+mkdir -p <%= ChefConfig::Config.etc_chef_dir(false) %>
<% 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)) %>
EOP
)) || exit 1
<% end -%>
<% 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 %>
EOP
)) || exit 1
<% end -%>
<% 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 %>
EOP
)) || exit 1
<% end -%>
<% unless trusted_certs.empty? -%>
-mkdir -p /etc/chef/trusted_certs
+mkdir -p <%= ChefConfig::Config.etc_chef_dir(false) %>/trusted_certs
<%= trusted_certs %>
<% end -%>
<%# Generate Ohai Hints -%>
<% 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| -%>
-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) %>
EOP
<% end -%>
<% end -%>
-cat > /etc/chef/client.rb <<'EOP'
+cat > <%= ChefConfig::Config.etc_chef_dir(false) %>/client.rb <<'EOP'
<%= config_content %>
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) %>
EOP
diff --git a/lib/chef/knife/core/windows_bootstrap_context.rb b/lib/chef/knife/core/windows_bootstrap_context.rb
index 977bfadc16..d3f55ce94c 100644
--- a/lib/chef/knife/core/windows_bootstrap_context.rb
+++ b/lib/chef/knife/core/windows_bootstrap_context.rb
@@ -59,9 +59,9 @@ class Chef
client_rb = <<~CONFIG
chef_server_url "#{@chef_config[:chef_server_url]}"
validation_client_name "#{@chef_config[:validation_client_name]}"
- file_cache_path "c:/chef/cache"
- file_backup_path "c:/chef/backup"
- cache_options ({:path => "c:/chef/cache/checksums", :skip_expires => true})
+ file_cache_path "#{ChefConfig::Config.var_chef_dir(true)}/cache"
+ file_backup_path "#{ChefConfig::Config.var_chef_dir(true)}/backup"
+ cache_options ({:path => "#{ChefConfig::Config.etc_chef_dir(true)}/cache/checksums", :skip_expires => true})
CONFIG
unless @chef_config[:chef_license].nil?
@@ -124,11 +124,11 @@ class Chef
end
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
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
if Chef::Config[:fips]
@@ -158,8 +158,8 @@ class Chef
def start_chef
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 << "chef-client -c c:/chef/client.rb -j c:/chef/first-boot.json#{bootstrap_environment_option}\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 #{ChefConfig::Config.etc_chef_dir(true)}/client.rb -j #{ChefConfig::Config.etc_chef_dir(true)}/first-boot.json#{bootstrap_environment_option}\n"
end
def win_wget
@@ -260,7 +260,7 @@ class Chef
end
def bootstrap_directory
- "C:\\chef"
+ ChefConfig::Config.etc_chef_dir(true)
end
def local_download_path