fnichol/knife-server

View on GitHub
lib/chef/knife/bootstrap/chef10/debian.erb

Summary

Maintainability
Test Coverage
bash <<'EOS'
<%
  require 'erb'

  def render(partial)
    partial_path = Gem.find_files(File.join(
      %W{chef knife bootstrap _#{partial}}
    )).first
    raise ArgumentError, "Partial _#{partial} not found" if partial_path.nil?

    ERB.new(IO.read(partial_path)).result(binding)
  end
-%>
set -e
<%= %{set -x} if @config[:knife] && @config[:knife][:log_level] == :debug -%>

<%=
  if knife_config[:bootstrap_proxy]
    %{export http_proxy="#{knife_config[:bootstrap_proxy]}"}
  end
-%>
export hostname="<%= @config[:chef_node_name] %>"
export webui_password="<%= ENV['WEBUI_PASSWORD'] %>"
export amqp_password="<%= ENV['AMQP_PASSWORD'] %>"

export DEBIAN_FRONTEND=noninteractive

<%= render "common.sh" %>

<%= render "platform_and_version.sh" %>

<%= render "set_hostname.sh" %>

setup() {
  apt-get update
  apt-get install -y lsb-release
}

add_opscode_apt_repo() {
  echo "deb http://apt.opscode.com/ $(lsb_release -cs)-0.10 main" > \
    /etc/apt/sources.list.d/opscode.list

  # add the GPG Key and Update Index
  mkdir -p /etc/apt/trusted.gpg.d
  apt-get update
  # permanent upgradeable keyring
  apt-get install -y --force-yes opscode-keyring
  apt-get dist-upgrade -y
}

preseed_chef_pkg() {
  local preseed=/var/cache/local/preseeding/chef-server.seed

  mkdir -p $(dirname $preseed)
  cat <<PRESEED > $preseed
chef    chef/chef_server_url    string    http://127.0.0.1:4000
chef-server-webui    chef-server-webui/admin_password    password    $webui_password
chef-solr    chef-solr/amqp_password    password    $amqp_password
PRESEED

  debconf-set-selections $preseed
}

install_chef_server() {
  preseed_chef_pkg

  apt-get update
  apt-get install -y chef chef-server libshadow-ruby1.8
}

config_chef_solo() {
  ## Configure Apache2 to proxy SSL traffic, using chef-solo
  local tmp_solo="$1"

  mkdir -p $tmp_solo
  cat > $tmp_solo/solo.rb <<SOLO_RB
file_cache_path "$tmp_solo"
cookbook_path   "$tmp_solo/cookbooks"
SOLO_RB

  cat <<BOOTSTRAP_JSON > $tmp_solo/bootstrap.json
{
  "chef_server" : {
    "webui_enabled" : true,
    "ssl_req" : "/C=CA/ST=Several/L=Locality/O=Example/OU=Operations/CN=${hostname}/emailAddress=root@${hostname}"
  },
  "run_list" : [ "recipe[chef-server::apache-proxy]" ]
}
BOOTSTRAP_JSON
}

enable_ssl_proxy() {
  local tmp_solo=/tmp/chef-solo

  config_chef_solo $tmp_solo

  chef-solo -c $tmp_solo/solo.rb -j $tmp_solo/bootstrap.json \
     -r http://s3.amazonaws.com/chef-solo/bootstrap-latest.tar.gz

  rm -rf $tmp_solo
}

setup
set_hostname_for_${platform}
add_opscode_apt_repo
install_chef_server
enable_ssl_proxy

banner "Bootstrapping Chef Server on ${hostname} is complete."
EOS