forked from SriniKancharla/cq-dev-server-provision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap_chef.sh
68 lines (53 loc) · 1.85 KB
/
bootstrap_chef.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
# call like this on the target server:
# NODENAME='foo' CHEF_ENV='production' bash < bootstrap_chef.sh
# You will need to ensure that the ssh key is already set up on the server.
set -e
#export CHEFREPO='srinikancharla@https://github.com/SriniKancharla:cq-dev-server-provision.git'
export CHEF_DIR="${HOME}/chef"
#export RUNLIST='["role[foo]","recipe[bar]"]'
export RUNLIST='[ "recipe[apt]", "recipe[basedevserv]" ]'
export CHEFREPO='[email protected]:SriniKancharla/cq-dev-server-provision'
sudo rm -rf $CHEF_DIR
mkdir -p "$CHEF_DIR"
echo "-- Installing Packages"
yes | sudo apt-get install ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential wget ssl-cert git-core
echo "-- Installing RubyGems"
if [[ ! (`command -v gem`) ]]; then
cd /tmp
wget -c http://production.cf.rubygems.org/rubygems/rubygems-1.7.2.tgz
tar zxf rubygems-1.7.2.tgz
cd rubygems-1.7.2
sudo ruby setup.rb --no-format-executable
fi
echo "-- Installing Chef gem"
if [[ ! (`command -v ohai` && `command -v chef-solo`) ]]; then
sudo gem install chef ohai --no-ri --no-rdoc
fi
mkdir -p "$HOME/.chef"
cat <<EOF > $HOME/.chef/knife.rb
log_level :debug
log_location STDOUT
node_name '$NODENAME'
cookbook_path [ '$CHEF_DIR/cookbooks', '$CHEF_DIR/site-cookbooks' ]
cookbook_copyright "Cheftest Inc."
EOF
echo "-- Cloning repository"
cd $CHEF_DIR
git clone $CHEFREPO .
echo "-- Setting up chef config"
cat <<EOF > $CHEF_DIR/config/solo.rb
log_level :debug
data_bag_path "$CHEF_DIR/data_bags"
file_cache_path "$CHEF_DIR"
cookbook_path "$CHEF_DIR/cookbooks"
role_path "$CHEF_DIR/roles"
json_attribs "$CHEF_DIR/config/default.json"
EOF
cat <<EOF > $CHEF_DIR/config/default.json
{ "chef_environment":"$CHEF_ENV","run_list": $RUNLIST }
EOF
printf "
=== Run the following ===
sudo chef-solo -c $CHEF_DIR/config/solo.rb
"