diff options
author | Thom May <thom@may.lt> | 2018-02-27 10:15:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-27 10:15:29 +0000 |
commit | e1f1bd24d23e7fc37aaf05e705d4d9cedff4d797 (patch) | |
tree | 2411b803c69db539a666b49a476610d5b32c1359 | |
parent | 41f248f286a4b12d64ef80c1855fdb17e2df73d8 (diff) | |
parent | 59086f0e757dd92b3b2b14ad21914091e281b498 (diff) | |
download | chef-e1f1bd24d23e7fc37aaf05e705d4d9cedff4d797.tar.gz |
Merge pull request #6861 from smcavallo/bootstrap_preinstall_command
Add support for knife bootstrap-preinstall-command
-rw-r--r-- | distro/common/html/knife_bootstrap.html | 2 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 5 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/templates/chef-full.erb | 6 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap_spec.rb | 12 |
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" ] } |