summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-08-21 16:18:32 -0700
committerSerdar Sutay <serdar@opscode.com>2014-08-26 15:42:26 -0700
commitb03b2aa547e6c9766d9ed39e29351540209c7b06 (patch)
tree668bff138214602ff1fb3024cba43abdb5d17cb2
parent63c044871c93c9ed3fa80536a036dc8642a78d0e (diff)
downloadchef-b03b2aa547e6c9766d9ed39e29351540209c7b06.tar.gz
Fixes based on the PR comments.
-rw-r--r--lib/chef/knife/bootstrap.rb9
-rw-r--r--lib/chef/knife/bootstrap/archlinux-gems.erb62
-rw-r--r--lib/chef/knife/core/bootstrap_context.rb15
3 files changed, 78 insertions, 8 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index d081a6b4d3..4440443821 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -75,6 +75,10 @@ class Chef
:long => "--node-name NAME",
:description => "The Chef node name for your new node"
+ option :prerelease,
+ :long => "--prerelease",
+ :description => "Install the pre-release chef gems"
+
option :bootstrap_version,
:long => "--bootstrap-version VERSION",
:description => "The version of Chef to install",
@@ -189,7 +193,10 @@ class Chef
template = Chef::Config[:knife][:bootstrap_template]
# Use the template directly if it's a path to an actual file
- return template if File.exists?(template)
+ if File.exists?(template)
+ Chef::Log.debug("Using the specified bootstrap template: #{File.dirname(bootstrap_template)}")
+ return template
+ end
# Otherwise search the template directories until we find the right one
diff --git a/lib/chef/knife/bootstrap/archlinux-gems.erb b/lib/chef/knife/bootstrap/archlinux-gems.erb
new file mode 100644
index 0000000000..bb84340c05
--- /dev/null
+++ b/lib/chef/knife/bootstrap/archlinux-gems.erb
@@ -0,0 +1,62 @@
+bash -c '
+<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
+
+if [ ! -f /usr/bin/chef-client ]; then
+ pacman -Syy
+ pacman -S --noconfirm ruby ntp base-devel
+ ntpdate -u pool.ntp.org
+ gem install ohai --no-user-install --no-document --verbose
+ gem install chef --no-user-install --no-document --verbose <%= Chef::VERSION %>
+fi
+
+mkdir -p /etc/chef
+
+cat > /etc/chef/validation.pem <<'EOP'
+<%= validation_key %>
+EOP
+chmod 0600 /etc/chef/validation.pem
+
+<% if encrypted_data_bag_secret -%>
+cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
+<%= encrypted_data_bag_secret %>
+EOP
+chmod 0600 /etc/chef/encrypted_data_bag_secret
+<% end -%>
+
+<%# Generate Ohai Hints -%>
+<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
+mkdir -p /etc/chef/ohai/hints
+
+<% @chef_config[:knife][:hints].each do |name, hash| -%>
+cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
+<%= hash.to_json %>
+EOP
+<% end -%>
+<% end -%>
+
+cat > /etc/chef/client.rb <<'EOP'
+log_level :info
+log_location STDOUT
+chef_server_url "<%= @chef_config[:chef_server_url] %>"
+validation_client_name "<%= @chef_config[:validation_client_name] %>"
+<% if @config[:chef_node_name] -%>
+node_name "<%= @config[:chef_node_name] %>"
+<% else -%>
+# Using default node name (fqdn)
+<% end -%>
+# ArchLinux follows the Filesystem Hierarchy Standard
+file_cache_path "/var/cache/chef"
+file_backup_path "/var/lib/chef/backup"
+pid_file "/var/run/chef/client.pid"
+cache_options({ :path => "/var/cache/chef/checksums", :skip_expires => true})
+<% if knife_config[:bootstrap_proxy] %>
+http_proxy "<%= knife_config[:bootstrap_proxy] %>"
+https_proxy "<%= knife_config[:bootstrap_proxy] %>"
+<% end -%>
+EOP
+
+cat > /etc/chef/first-boot.json <<'EOP'
+<%= first_boot.to_json %>
+EOP
+
+<%= start_chef %>'
diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb
index 5781481b40..4583766bf3 100644
--- a/lib/chef/knife/core/bootstrap_context.rb
+++ b/lib/chef/knife/core/bootstrap_context.rb
@@ -98,17 +98,18 @@ CONFIG
# If user is on X.Y.Z bootstrap will use the latest X release
# X here can be 10 or 11
def latest_current_chef_version_string
- chef_version_string = if knife_config[:bootstrap_version]
- knife_config[:bootstrap_version]
+ installer_version_string = nil
+ if config[:prerelease]
+ installer_version_string = "-p"
else
Chef::VERSION.split(".").first
end
+ installer_version_string = ["-v", chef_version_string]
- installer_version_string = ["-v", chef_version_string]
-
- # If bootstrapping a pre-release version add -p to the installer string
- if chef_version_string.split(".").length > 3
- installer_version_string << "-p"
+ # If bootstrapping a pre-release version add -p to the installer string
+ if chef_version_string.split(".").length > 3
+ installer_version_string << "-p"
+ end
end
installer_version_string.join(" ")