Skip to content

Instantly share code, notes, and snippets.

@stathy
Last active December 14, 2015 01:19
Show Gist options
  • Save stathy/5005351 to your computer and use it in GitHub Desktop.
Save stathy/5005351 to your computer and use it in GitHub Desktop.
Custom bootstrap template for user space install. rvm + ruby + chef gem 2 variables to define and align omnibus ruby version and chef version.
bash -c '
ruby_version="1.9.3-p374"
chef_version="11.4.0-1"
# Comment line above, uncomment below, to default to knife 'chef' version
#chef_version="<%= %Q(#{knife_config[:bootstrap_version]}) %>"
<%= %Q(export http_proxy="#{knife_config[:bootstrap_proxy]}") if knife_config[:bootstrap_proxy] %>
exists() {
if command -v $1 &>/dev/null
then
return 0
else
return 1
fi
}
if ! exists ~/.rvm/scripts/rvm ; then
if exists curl; then
curl -L "https://get.rvm.io" | bash -s stable
echo "SUCCESS: Installed latest stable rvm" `rvm --version`
else
echo "ERROR: curl is not available to download rvm" 1>&2
exit 1
fi
fi
source ~/.rvm/scripts/rvm
if ! exists ~/.rvm/gems/ruby-${ruby_version}/bin/ruby ; then
rvm install ruby-${ruby_version}
echo SUCCESS: Installed ruby version `ruby --version`
fi
rvm --default use ${ruby_version}
if ! exists ~/.rvm/gems/ruby-${ruby_version}@${chef_version}/bin/chef-client ; then
rvm gemset create ${chef_version}
rvm use ${ruby_version}@${chef_version} --default
gem update --system
gem update
gem install ohai --no-rdoc --no-ri --verbose
gem install chef --no-rdoc --no-ri --verbose <%= ENV['chef_version'] || bootstrap_version_string %>
echo SUCCESS: Installed chef gem version `chef-client --version`
fi
rvm use ${ruby_version}@${chef_version} --default
mkdir -v -p ~/.chef
(
cat <<'EOP'
<%= validation_key %>
EOP
) > /tmp/validation.pem
awk NF /tmp/validation.pem > ~/.chef/validation.pem
rm /tmp/validation.pem
<% if @chef_config[:encrypted_data_bag_secret] -%>
awk NF > ~/.chef/encrypted_data_bag_secret <<'EOP'
<%= encrypted_data_bag_secret %>
EOP
chmod 0600 ~/.chef/encrypted_data_bag_secret
<% end -%>
<%# Generate Ohai Hints -%>
<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
mkdir -p ~/.chef/ohai/hints
<% @chef_config[:knife][:hints].each do |name, hash| -%>
cat > ~/.chef/ohai/hints/<%= name %>.json <<'EOP'
<%= hash.to_json %>
EOP
<% end -%>
<% end -%>
mkdir -v -p ~/.chef/checksums
mkdir -v -p ~/.chef/cache
mkdir -v -p ~/.chef/backup
mkdir -v -p ~/.chef/logs
mkdir -v -p ~/.chef/node
mkdir -v -p ~/.chef/run
mkdir -v -p ~/.chef/certs
(
cat <<'EOP'
<%= config_content %>
current_dir = File.dirname(__FILE__)
client_key "#{current_dir}/client.pem"
validation_key "#{current_dir}/validation.pem"
file_cache_path "#{current_dir}/cache"
file_backup_path "#{current_dir}/backup"
log_location "#{current_dir}/logs/client.log"
node_path "#{current_dir}/node"
pid_file "#{current_dir}/run"
ssl_ca_path "#{current_dir}/certs"
EOP
) > ~/.chef/client.rb
(
cat <<'EOP'
<%= { "run_list" => @run_list }.to_json %>
EOP
) > ~/.chef/first-boot.json
<%= start_chef %> --config ~/.chef/client.rb --json-attributes ~/.chef/first-boot.json
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment