-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
62 lines (51 loc) · 1.32 KB
/
bootstrap.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
#!/bin/bash
function create_clientrb {
/bin/cat > $1 <<EOF
log_level :info
log_location STDOUT
chef_server_url '$2'
validation_key '/etc/chef/validation.pem'
validation_client_name 'onecloud-validator'
ssl_verify_mode :verify_none
EOF
}
function create_firstbootjson {
/bin/cat > $1 <<EOF
{
"run_list": ["recipe[$2]"]
}
EOF
}
DATE=`/bin/date +"%H.%M.%s-%m-%d-%Y"`
OUTDIR=/root/prov-logs
OUTLOG=$OUTDIR/bootstrap-$DATE.log
if [[ ! -d $OUTDIR ]] # Check to see if the provisioning log directory exists
then
/bin/mkdir -p $OUTDIR
fi
# initialize the logfile
> $OUTLOG
if [ $# -lt 4 ];
then
echo "Usage: $0 <Datacenter> <Service-Level> <Roles> <Url>"
exit 1
fi
CHEFDIR=/etc/chef
CLIENTRBFILE=$CHEFDIR/client.rb
FIRSTBOOTJSON=$CHEFDIR/first-boot.json
DATACENTER=$1
SERVICELEVEL=$2
CHEFSERVERURL=$4
CHEFROLES=$3
if [[ ! -d $CHEFDIR ]] # Check to see if chef directory exists
then
/bin/mkdir -p $CHEFDIR
fi
/bin/cp /tmp/validation.pem $CHEFDIR/validation.pem
echo "Chef directory $CHEFDIR created successfully." >> $OUTLOG
create_clientrb $CLIENTRBFILE $CHEFSERVERURL
echo "Client Rb file created successfully with Chef Server Url $CHEFSERVERURL." >> $OUTLOG
create_firstbootjson $FIRSTBOOTJSON $3
echo "First boot json file created successfully." >> $OUTLOG
chef-client -j $FIRSTBOOTJSON --environment $1
exit 0