summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorS.Cavallo <smcavallo@hotmail.com>2018-02-15 11:02:17 -0500
committerS.Cavallo <smcavallo@hotmail.com>2018-02-15 11:02:17 -0500
commit59086f0e757dd92b3b2b14ad21914091e281b498 (patch)
tree52e5626400aa9edd11dcaeb752381fdd7eda97eb
parent01ae5aac80444d6e849bb44ba0f5798e46978c7f (diff)
downloadchef-59086f0e757dd92b3b2b14ad21914091e281b498.tar.gz
Add support for knife bootstrap-preinstall-command
Signed-off-by: S. Cavallo <smcavallo@hotmail.com>
-rw-r--r--distro/common/html/knife_bootstrap.html2
-rw-r--r--lib/chef/knife/bootstrap.rb5
-rw-r--r--lib/chef/knife/bootstrap/templates/chef-full.erb6
-rw-r--r--spec/unit/knife/bootstrap_spec.rb12
4 files changed, 25 insertions, 0 deletions
diff --git a/distro/common/html/knife_bootstrap.html b/distro/common/html/knife_bootstrap.html
index 7589dfbaba..cf5edb95bc 100644
--- a/distro/common/html/knife_bootstrap.html
+++ b/distro/common/html/knife_bootstrap.html
@@ -66,6 +66,8 @@
<dd>Use to enable SSH agent forwarding.</dd>
<dt><tt class="docutils literal"><span class="pre">--bootstrap-curl-options</span> <span class="pre">OPTIONS</span></tt></dt>
<dd>Use to specify arbitrary options to be added to the bootstrap command when using cURL. This option may not be used in the same command with <tt class="docutils literal"><span class="pre">--bootstrap-install-command</span></tt>.</dd>
+<dt><tt class="docutils literal"><span class="pre">--bootstrap-preinstall-command</span> <span class="pre">COMMAND</span></tt></dt>
+<dd>Use to execute a custom command before installation of the chef-client.</dd>
<dt><tt class="docutils literal"><span class="pre">--bootstrap-install-command</span> <span class="pre">COMMAND</span></tt></dt>
<dd>Use to execute a custom installation command sequence for the chef-client. This option may not be used in the same command with <tt class="docutils literal"><span class="pre">--bootstrap-curl-options</span></tt>, <tt class="docutils literal"><span class="pre">--bootstrap-install-sh</span></tt>, or <tt class="docutils literal"><span class="pre">--bootstrap-wget-options</span></tt>.</dd>
<dt><tt class="docutils literal"><span class="pre">--bootstrap-install-sh</span> <span class="pre">URL</span></tt></dt>
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index 9decacce13..88656359f9 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -219,6 +219,11 @@ class Chef
:description => "Custom command to install chef-client",
:proc => Proc.new { |ic| Chef::Config[:knife][:bootstrap_install_command] = ic }
+ option :bootstrap_preinstall_command,
+ :long => "--bootstrap-preinstall-command COMMANDS",
+ :description => "Custom commands to run before installing chef-client",
+ :proc => Proc.new { |preic| Chef::Config[:knife][:bootstrap_preinstall_command] = preic }
+
option :bootstrap_wget_options,
:long => "--bootstrap-wget-options OPTIONS",
:description => "Add options to wget when installing chef-client",
diff --git a/lib/chef/knife/bootstrap/templates/chef-full.erb b/lib/chef/knife/bootstrap/templates/chef-full.erb
index 145761a39e..c80a3aa4ff 100644
--- a/lib/chef/knife/bootstrap/templates/chef-full.erb
+++ b/lib/chef/knife/bootstrap/templates/chef-full.erb
@@ -162,6 +162,12 @@ do_download() {
return 16
}
+<%# Run any custom commands before installing chef-client -%>
+<%# Ex. wait for cloud-init to complete -%>
+<% if knife_config[:bootstrap_preinstall_command] %>
+ <%= knife_config[:bootstrap_preinstall_command] %>
+<% end %>
+
<% if knife_config[:bootstrap_install_command] %>
<%= knife_config[:bootstrap_install_command] %>
<% else %>
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index c725526de7..ea4c177d55 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -84,6 +84,18 @@ describe Chef::Knife::Bootstrap do
end
end
+ context "with --bootstrap-preinstall-command" do
+ command = "while sudo fuser /var/lib/dpkg/lock >/dev/null 2>&1; do\n echo 'waiting for dpkg lock';\n sleep 1;\n done;"
+ let(:bootstrap_cli_options) { [ "--bootstrap-preinstall-command", command ] }
+ let(:rendered_template) do
+ knife.merge_configs
+ knife.render_template
+ end
+ it "configures the preinstall command in the bootstrap template correctly" do
+ expect(rendered_template).to match(%r{command})
+ end
+ end
+
context "with :distro and :bootstrap_template cli options" do
let(:bootstrap_cli_options) { [ "--bootstrap-template", "my-template", "--distro", "other-template" ] }