-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_chef_solo.sh
executable file
·83 lines (68 loc) · 1.83 KB
/
run_chef_solo.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# run_chef_solo.sh
# Author: abento+github@gmail.com
# Setup a set of cookbooks using chef-solo on a remote machine.
cookbook_root="."
file_root="chef-solo"
tmp_root="."
installChefSolo() {
ssh -qt $1 "which chef-solo" >/dev/null 2>&1
if [ $? -ne 0 ]; then
rpms="ruby rubygems ruby-devel ruby-ri ruby-rdoc ruby-shadow gcc gcc-c++ automake autoconf make curl dmidecode openssh-clients"
gems="chef"
echo "Pushing chef-solo config to host $1"
ssh -t $1 "sudo hostname $1"
ssh -t $1 "sudo yum -y install $rpms"
ssh -t $1 "sudo gem install $gems --no-ri --no-rdoc"
echo "chef-solo install complete for host $1"
else
echo "chef-solo already installed. Skipping installation."
return 0
fi
}
pushConfig()
{
echo "Pushing chef-solo config to host $1"
solo_file=$file_root/solo.rb
runlist_file=$file_root/run_list.json
if [ -f $solo_file ]; then
scp $solo_file $1: >/dev/null 2>&1
else
echo "$solo_file doesn't exist."
exit 1
fi
if [ -f $runlist_file ]; then
scp $runlist_file $1: >/dev/null 2>&1
else
echo "$runlist_file doesn't exist."
exit 1
fi
scp $ $1: >/dev/null 2>&1
echo "Taring up cookbooks..."
COPYFILE_DISABLE=1 tar zcLf $tmp_root/solo_cookbooks.tgz $cookbook_root/cookbooks
if [ $? -ne 0 ]; then
echo "Problems creating tarball."
exit 1
fi
echo "Sending up cookbook tarball..."
scp $tmp_root/solo_cookbooks.tgz $1: >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Problems push tarball to $1."
exit 1
fi
}
runChefSolo()
{
echo "Running chef-solo on host $1"
ssh -t $1 "sudo chef-solo -c ./solo.rb -j ./run_list.json -r ./solo_cookbooks.tgz"
}
if [ "$1" ]
then
installChefSolo $1
pushConfig $1
runChefSolo $1
else
echo "usage: $0 <hostname>"
exit 3
fi
echo "chef-solo push and config run complete"