Last active
May 8, 2016 16:24
-
-
Save swobspace/5494338 to your computer and use it in GitHub Desktop.
Bootstrap file for installing ruby, opscode chef, librarian-chef and related stuff on a minimal installed fedora or ubuntu machine for using chef-solo locally.
This file contains hidden or 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 ruby version | |
VER=2.3 | |
RUBYVERSION=${VER}.1 | |
CHEFDIR=/var/lib/chef | |
export PATH=/usr/local/sbin:/usr/local/bin:$PATH | |
DISTRIBUTION=`lsb_release -si` | |
mkdir -p $CHEFDIR; cd $CHEFDIR | |
# ------------------------------------------------- | |
# basic packages | |
case "$DISTRIBUTION" in | |
Fedora) | |
dnf update | |
dnf install openssl-devel zlib-devel libyaml-devel git readline-devel | |
;; | |
Debian|Ubuntu) | |
apt-get -y update | |
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev git | |
;; | |
*) | |
echo "Distribution $DISTRIBUTION not yet supported" | |
exit 1 | |
esac | |
# ------------------------------------------------- | |
# install ruby | |
if [ "$RUBYVERSION" != "system" ]; then | |
$(\ | |
cd /tmp; \ | |
wget http://ftp.ruby-lang.org/pub/ruby/${VER}/ruby-${RUBYVERSION}.tar.gz ;\ | |
tar -xvzf ruby-${RUBYVERSION}.tar.gz ;\ | |
cd ruby-${RUBYVERSION}/ ;\ | |
./configure --prefix=/usr/local --enable-shared && make && make install ; \ | |
) | |
hash -r | |
# -- check ruby version | |
echo " --- " | |
ruby -v | |
echo " --- " | |
sleep 5 | |
fi | |
# -------------------------------------------------------------------------------- | |
# .gemrc for root | |
cat > $HOME/.gemrc << EOF_GEMRC | |
--- | |
# http_proxy: http://192.0.2.1:3128/ | |
:update_sources: true | |
:sources: | |
- https://rubygems.org/ | |
:benchmark: false | |
:bulk_threshold: 1000 | |
:backtrace: false | |
:verbose: true | |
# gem: --no-ri --no-rdoc | |
install: --no-ri --no-rdoc --env-shebang | |
update: --no-rdoc --no-ri --env-shebang | |
EOF_GEMRC | |
# -------------------------------------------------------------------------------- | |
# installing chef, librarian-chef and bundler | |
gem install chef ruby-shadow bundler --no-ri --no-rdoc --env-shebang | |
gem install librarian-chef --no-ri --no-rdoc --env-shebang | |
# -------------------------------------------------------------------------------- | |
# .gitignore : | |
# with vagrant you should set this in your vagrant machine directory | |
# and stop the procedure here | |
cat > $CHEFDIR/.gitignore << EOF_GITIGNORE | |
/cookbooks | |
/tmp | |
*.swp | |
/bootstrap | |
/vagrant | |
EOF_GITIGNORE | |
# -------------------------------------------------------------------------------- | |
# create a solo.rb for chef-solo: | |
# - cookbooks is only for librarian-chef cookbooks | |
# - local cookbooks goes to site-cookbook | |
cat > $CHEFDIR/solo.rb << SOLO_EOF | |
http_proxy "#{ENV['http_proxy']}" | |
https_proxy "#{ENV['http_proxy']}" | |
cookbook_path [ | |
File.expand_path("../cookbooks", __FILE__), | |
File.expand_path("../site-cookbooks", __FILE__), | |
] | |
json_attribs File.expand_path("../node.json", __FILE__) | |
SOLO_EOF | |
echo "Done. Please check $CHEFDIR/solo.rb, $CHEFDIR/.gitignore and $HOME/.gemrc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment