2014-11-19 14:42:19 +00:00
|
|
|
#!/bin/bash
|
2013-04-08 06:27:25 +00:00
|
|
|
# IBM(c) 2013 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#=head1 config_chef_workstation
|
|
|
|
#=head2 This command configures the chef workstation on a xCAT node.
|
|
|
|
# It is used by install_chef_workstation on Ubuntu and chef kit on RH.
|
|
|
|
#=cut
|
|
|
|
#-------------------------------------------------------------------------------
|
2013-12-17 19:16:58 +00:00
|
|
|
HOME='/root/'
|
|
|
|
export HOME
|
2013-04-08 06:27:25 +00:00
|
|
|
|
|
|
|
node=`hostname`
|
|
|
|
|
2013-11-11 21:11:18 +00:00
|
|
|
uselocalhost=0
|
2013-04-08 06:27:25 +00:00
|
|
|
# Who is the chef server?
|
|
|
|
# -s takes precedence
|
|
|
|
# then site.chefserver
|
|
|
|
# then site.master
|
|
|
|
ARGNUM=$#;
|
|
|
|
if [ $ARGNUM -gt 1 ]; then
|
|
|
|
if [ $1 = "-s" ]; then
|
|
|
|
chefserver=$2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$chefserver" ]
|
|
|
|
then
|
2013-07-05 03:20:19 +00:00
|
|
|
if [ -n "$CFGSERVER" -a -n "$CFGMGR" ]; then
|
|
|
|
if [ $CFGMGR = "chef" ]; then
|
|
|
|
chefserver=$CFGSERVER
|
|
|
|
fi
|
2013-07-05 02:11:01 +00:00
|
|
|
fi
|
|
|
|
if [ -z "$chefserver" ]
|
2013-04-08 06:27:25 +00:00
|
|
|
then
|
|
|
|
chefserver=$CHEFSERVER
|
|
|
|
fi
|
|
|
|
if [ -z "$chefserver" ]
|
|
|
|
then
|
2013-10-22 14:22:39 +00:00
|
|
|
chefserver=$MASTER
|
2013-04-08 06:27:25 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$chefserver" ]
|
|
|
|
then
|
|
|
|
# No chef server defined, using localhost is the only choice
|
|
|
|
uselocalhost=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
localip=`getent hosts \`hostname\` | awk '{print $1}'`
|
|
|
|
serverip=`getent hosts $chefserver | awk '{print $1}'`
|
|
|
|
|
|
|
|
if [ "$localip" = "$serverip" ]
|
|
|
|
then
|
|
|
|
uselocalhost=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check if the current node is also a chef master
|
|
|
|
# if yes, use this node as the chef server
|
|
|
|
if [ -f /etc/chef-server/admin.pem ]; then
|
|
|
|
uselocalhost=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
homedir=$HOME
|
|
|
|
# In prereboot, the HOME is /tmp
|
|
|
|
# assume root
|
|
|
|
if [ "$homedir" = "/tmp" ] || [ -z "$homedir" ]
|
|
|
|
then
|
|
|
|
homedir=/root
|
|
|
|
fi
|
|
|
|
# Reconfigure the ~/.chef
|
|
|
|
rm -rf $homedir/.chef.bak >/dev/null 2>&1
|
|
|
|
mv $homedir/.chef $homedir/.chef.bak >/dev/null 2>&1
|
|
|
|
mkdir $homedir/.chef
|
|
|
|
|
|
|
|
if [ $uselocalhost = 1 ]
|
|
|
|
then
|
|
|
|
chefserver=$localip
|
|
|
|
client_key='/etc/chef-server/admin.pem'
|
|
|
|
validation_key='/etc/chef-server/chef-validator.pem'
|
|
|
|
else
|
|
|
|
# Remote chef-server
|
2013-10-22 14:22:39 +00:00
|
|
|
#scp $chefserver:/etc/chef-server/admin.pem $homedir/.chef 2>&1 1>/dev/null
|
|
|
|
#scp $chefserver:/etc/chef-server/chef-validator.pem $homedir/.chef 2>&1 1>/dev/null
|
|
|
|
mkdir -p /etc/chef
|
|
|
|
mkdir -p /etc/chef-server_tmp
|
|
|
|
|
|
|
|
mount $chef_server:/etc/chef-server /etc/chef-server_tmp
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
errmsg="Failed to run 'mount $chef_server:/etc/chef-server /etc/chef-server_tmp' on $node"
|
|
|
|
logger -t xcat -p local4.err $errmsg
|
|
|
|
echo $errmsg
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
cp /etc/chef-server_tmp/admin.pem $homedir/.chef 2>&1 1>/dev/null
|
|
|
|
cp /etc/chef-server_tmp/chef-validator.pem $homedir/.chef 2>&1 1>/dev/null
|
|
|
|
umount /etc/chef-server_tmp
|
|
|
|
rmdir /etc/chef-server_tmp
|
2013-04-08 06:27:25 +00:00
|
|
|
if [ ! -e "$homedir/.chef/admin.pem" ] || [ ! -e "$homedir/.chef/chef-validator.pem" ]
|
|
|
|
then
|
|
|
|
errmsg="Could not get the chef keys from chef server $chefserver"
|
|
|
|
logger -t xcat -p local4.err $errmsg
|
|
|
|
echo $errmsg
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -e "log_level :info
|
|
|
|
log_location STDOUT
|
|
|
|
node_name 'admin'
|
|
|
|
client_key '$client_key'
|
|
|
|
validation_client_name 'chef-validator'
|
|
|
|
validation_key '$validation_key'
|
|
|
|
chef_server_url 'https://$chefserver'" > $homedir/.chef/knife.rb
|
|
|
|
|
|
|
|
# Verify the configuration
|
|
|
|
knife client list
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
errmsg="Failed to onfigure chef worktation on $node"
|
|
|
|
logger -t xcat -p local4.err $errmsg
|
|
|
|
echo $errmsg
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-04-08 06:31:35 +00:00
|
|
|
|
2013-04-08 06:27:25 +00:00
|
|
|
exit 0
|