-
-
Save thomseddon/5080906 to your computer and use it in GitHub Desktop.
Convert https://gist.github.com/fnichol/1209226 for RPM based distros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
set -x | |
### How To Use | |
# | |
# sudo bash -c 'bash \ | |
# <(curl -sLB https://raw.github.com/gist/5080906/bootstrap_chef_server_rpm.sh) \ | |
# --hostname foo.example.com' | |
# | |
# Details pulled from: | |
# http://wiki.opscode.com/display/chef/Bootstrap+Chef+RubyGems+Installation | |
log() { printf "===> $*\n" ; return $? ; } | |
fail() { log "\nERROR: $*\n" ; exit 1 ; } | |
usage() { | |
printf " | |
Usage | |
bootstrap_chef_server.sh [options] [action] | |
Options | |
--hostname|-h <foo.example.com> - Sets the FQDN of host node | |
Actions | |
help - Display CLI help (this output) | |
" | |
} | |
set_hostname() { | |
if hostname | grep -q "$__hostname" >/dev/null ; then | |
log "Hostname is correct, so skipping..." | |
return | |
fi | |
hostname $__hostname | |
echo 127.0.0.1 $__hostname >> /etc/hosts | |
} | |
install_ruby_packages() { | |
yum install -y ruby ruby-devel rubygems ruby-rdoc ruby-ri ruby-irb gcc wget make | |
} | |
install_chef() { | |
gem install ohai --no-ri --no-rdoc | |
gem install chef --no-ri --no-rdoc | |
} | |
build_chef_solo_config() { | |
mkdir -p /etc/chef | |
cat > /etc/chef/solo.rb <<SOLO_RB | |
file_cache_path "/tmp/chef-solo" | |
cookbook_path "/tmp/chef-solo/cookbooks" | |
SOLO_RB | |
cat > /etc/chef/bootstrap.json <<BOOTSTRAP_JSON | |
{ | |
"chef_server": { | |
"server_url": "http://localhost:4000", | |
"webui_enabled": true | |
}, | |
"build-essential": { | |
"compiletime": true | |
}, | |
"run_list": [ "recipe[build-essential]","recipe[chef-server::rubygems-install]" ] | |
} | |
BOOTSTRAP_JSON | |
} | |
run_chef_solo() { | |
chef-solo -c /etc/chef/solo.rb -j /etc/chef/bootstrap.json -r https://s3.amazonaws.com/chef-solo/bootstrap-latest.tar.gz | |
} | |
# Parse CLI arguments | |
while [[ $# -gt 0 ]] ; do | |
token="$1" | |
shift | |
case "$token" in | |
--hostname|-h) | |
case "$1" in | |
*.*) | |
__hostname="$1" | |
shift | |
;; | |
*) | |
fail "--hostname must be followed by a FQDN, i.e. foo.example.com" | |
;; | |
esac | |
;; | |
help|usage) | |
usage | |
exit 0 | |
;; | |
*) | |
usage | |
exit 1 | |
;; | |
esac | |
done | |
if [[ -z "$__hostname" ]] ; then | |
fail "--hostname is a required option" | |
fi | |
# Perform the actual bootstrap | |
set_hostname | |
install_ruby_packages | |
install_chef | |
build_chef_solo_config | |
run_chef_solo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment