summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2016-02-04 16:46:25 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2016-02-24 21:24:14 -0800
commitd0f2106071bf6cd8caf41555fe1a1784b3aff1fa (patch)
tree14a060e04917b139d4499542f41c7557654df3c4 /lib
parent0584f32a8cbc82db9b1361e7a3a9f42bfbe5af51 (diff)
downloadchef-d0f2106071bf6cd8caf41555fe1a1784b3aff1fa.tar.gz
Copy client.d files during bootstrap
When knife finds a client.d/ directory, it will upload all files nested under that directory.
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/knife/bootstrap/templates/chef-full.erb5
-rw-r--r--lib/chef/knife/core/bootstrap_context.rb25
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/chef/knife/bootstrap/templates/chef-full.erb b/lib/chef/knife/bootstrap/templates/chef-full.erb
index 020645c869..6007ff9859 100644
--- a/lib/chef/knife/bootstrap/templates/chef-full.erb
+++ b/lib/chef/knife/bootstrap/templates/chef-full.erb
@@ -226,6 +226,11 @@ cat > /etc/chef/first-boot.json <<EOP
<%= Chef::JSONCompat.to_json(first_boot) %>
EOP
+<% unless client_d.empty? -%>
+mkdir -p /etc/chef/client.d
+<%= client_d %>
+<% end -%>
+
echo "Starting the first Chef Client run..."
<%= start_chef %>'
diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb
index b05cae688c..6f1c234796 100644
--- a/lib/chef/knife/core/bootstrap_context.rb
+++ b/lib/chef/knife/core/bootstrap_context.rb
@@ -18,6 +18,7 @@
require "chef/run_list"
require "chef/util/path_helper"
+require "pathname"
class Chef
class Knife
@@ -52,6 +53,10 @@ class Chef
end
end
+ def client_d
+ @cliend_d ||= client_d_content
+ end
+
def encrypted_data_bag_secret
@secret
end
@@ -195,6 +200,26 @@ validation_client_name "#{@chef_config[:validation_client_name]}"
content
end
+ def client_d_content
+ content = ""
+ if @chef_config[:client_d_dir] && File.exist?(@chef_config[:client_d_dir])
+ root = Pathname(@chef_config[:client_d_dir])
+ root.find do |f|
+ relative = f.relative_path_from(root)
+ if f != root
+ file_on_node = "/etc/chef/client.d/#{relative}"
+ if f.directory?
+ content << "mkdir #{file_on_node}\n"
+ else
+ content << "cat > #{file_on_node} <<'EOP'\n" +
+ f.read + "\nEOP\n"
+ end
+ end
+ end
+ end
+ content
+ end
+
end
end
end