Skip to content

Instantly share code, notes, and snippets.

@bryanstearns
Created July 31, 2012 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanstearns/3212198 to your computer and use it in GitHub Desktop.
Save bryanstearns/3212198 to your computer and use it in GitHub Desktop.
Customized bootstrap to add the private IP address to /etc/network/interfaces and set up Linsides' apt-cacher proxy
bash -c '
<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
<% private_ip = (@config[:first_boot_attributes]["ip_addresses"] || []).select{|x| x =~ /^192.168/ }.first
if private_ip -%>
function add_private_network_and_proxy() {
cat <<'EOP' >>/etc/network/interfaces
auto eth0:0
iface eth0:0 inet static
address <%= private_ip %>
netmask 255.255.128.0
EOP
ifconfig eth0:0 <%= private_ip %> netmask 255.255.128.0 up
<% # If we're in the right datacenter, we can use the Linsides apt cache
# see: https://linsides.com/services/aptcache/
datacenter = { # only works in newark or dallas
'2' => 'dallas',
'6' => 'newark'
}[@config[:first_boot_attributes]["linode_datacenter_id"].to_s]
if datacenter %>
cat >/etc/apt/apt.conf.d/01proxy <<'EOP'
Acquire::http { Proxy "http://apt-cache.<%= datacenter %>.linsides.com:3142"; };
EOP
<% end -%>
}
grep -q eth0:0 /etc/network/interfaces || add_private_network_and_proxy
<% end -%>
if [ ! -f /usr/bin/chef-client ]; then
apt-get update
apt-get install -y ruby ruby1.8-dev build-essential wget libruby1.8 rubygems
fi
gem update --no-rdoc --no-ri
gem install ohai --no-rdoc --no-ri --verbose
gem install chef --no-rdoc --no-ri --verbose <%= bootstrap_version_string %>
mkdir -p /etc/chef
(
cat <<'EOP'
<%= validation_key %>
EOP
) > /tmp/validation.pem
awk NF /tmp/validation.pem > /etc/chef/validation.pem
rm /tmp/validation.pem
<% if @chef_config[:encrypted_data_bag_secret] -%>
(
cat <<'EOP'
<%= encrypted_data_bag_secret %>
EOP
) > /tmp/encrypted_data_bag_secret
awk NF /tmp/encrypted_data_bag_secret > /etc/chef/encrypted_data_bag_secret
rm /tmp/encrypted_data_bag_secret
<% end -%>
(
cat <<'EOP'
<%= config_content %>
EOP
) > /etc/chef/client.rb
(
cat <<'EOP'
<%= @config[:first_boot_attributes].merge("run_list" => @run_list).to_json %>
EOP
) > /etc/chef/first-boot.json
<%= start_chef %>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment