From 7211b9c3d57d70abae746894f4a8d0c38204ef63 Mon Sep 17 00:00:00 2001 From: linggao Date: Fri, 29 Mar 2013 19:04:31 +0000 Subject: [PATCH] Added code for xCAT puppet integration on Ubuntu. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.8@15733 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT/postscripts/config_puppet_client | 90 +++++++++++++++++++++ xCAT/postscripts/config_puppet_server | 108 +++++++++++++++++++++++++ xCAT/postscripts/install_puppet_client | 105 ++++++++++++++++++++++++ xCAT/postscripts/install_puppet_server | 97 ++++++++++++++++++++++ 4 files changed, 400 insertions(+) create mode 100755 xCAT/postscripts/config_puppet_client create mode 100755 xCAT/postscripts/config_puppet_server create mode 100755 xCAT/postscripts/install_puppet_client create mode 100755 xCAT/postscripts/install_puppet_server diff --git a/xCAT/postscripts/config_puppet_client b/xCAT/postscripts/config_puppet_client new file mode 100755 index 000000000..3bea76930 --- /dev/null +++ b/xCAT/postscripts/config_puppet_client @@ -0,0 +1,90 @@ +#!/bin/sh +# IBM(c) 2013 EPL license http://www.eclipse.org/legal/epl-v10.html + + +#------------------------------------------------------------------------------- +#=head1 config_puppet_client +#=head2 This command configure the puppet client on a xCAT node. +# It is used by install_puppet_client on Ubuntu and puppet kit on RH. +#=cut +#------------------------------------------------------------------------------- + +echo "Configuring pupper client....." +#check if the current node is also a puppet master +ismaster=0 +if [ -f /etc/puppet/fileserver.conf ]; then + ismaster=1 +fi + +#configure the puppet.conf file. +#the pupper server can be passed as an argument or as an environmental variable +#the default is $SITEMASTER +ARGNUM=$#; +if [ $ARGNUM -gt 1 ]; then + if [ $2 = "-s" ]; then + puppet_server=$2 + fi +else + if [ -n "$PUPPETSERVER" ]; then + puppet_server=$PUPPETSERVER + fi +fi +if [ -z "$puppet_server" ]; then + puppet_server=$SITEMASTER +fi + +echo "puppet_server=$puppet_server" + +confname="/etc/puppet/puppet.conf" +if [ ! -f "$confname" ]; then + touch $confname +else + cp -f $confname ${confname}.save + #remove the old configuration if any + sed -i "/# xcat-added-agent-section-start-here/,/# xcat-added-agent-section-end-here/ d" $confname + sed -i "/# xcat-added-main-section-start-here/,/# xcat-added-main-section-end-here/ d" $confname +fi + +if [ $ismaster -ne 1 ]; then + grep "\[main\]" $confname + if [ $? -eq 0 ]; then + sed -i "/\[main\]/ a\ + # xcat-added-main-section-end-here #" $confname + sed -i "/\[main\]/ a\ + certname = $NODE" $confname + sed -i "/\[main\]/ a\ + # xcat-added-main-section-start-here #" $confname + else + echo "[main]" >> $confname + echo "# xcat-added-main-section-start-here #" >> $confname + echo " certname=$NODE" >> $confname + echo "# xcat-added-main-section-end-here #" >> $confname + fi +fi + +grep "\[agent\]" $confname +if [ $? -eq 0 ]; then + sed -i "/\[agent\]/ a\ + # xcat-added-agent-section-end-here #" $confname + sed -i "/\[agent\]/ a\ + server = $puppet_server" $confname + sed -i "/\[agent\]/ a\ + pluginsync = true" $confname + sed -i "/\[agent\]/ a\ + # xcat-added-agent-section-start-here #" $confname +else + echo " " >> $confname + echo "[agent]" >> $confname + echo "# xcat-added-agent-section-start-here #" >> $confname + echo " pluginsync = true" >> $confname + echo " server = $puppet_server" >> $confname + echo "# xcat-added-agent-section-end-here #" >> $confname +fi + +exit 0 + + + + + + diff --git a/xCAT/postscripts/config_puppet_server b/xCAT/postscripts/config_puppet_server new file mode 100755 index 000000000..fff6373c4 --- /dev/null +++ b/xCAT/postscripts/config_puppet_server @@ -0,0 +1,108 @@ +#!/bin/sh +# IBM(c) 2013 EPL license http://www.eclipse.org/legal/epl-v10.html + + +#------------------------------------------------------------------------------- +#=head1 config_puppet_server +#=head2 This command configures the puppet server on a xCAT server or node. +# It is used by install_puppet_server on Ubuntu and puppet kit on RH. +#=cut +#------------------------------------------------------------------------------- + + +#Now configure the pupper server +echo "Configuring pupper server....." +#remove old certificate +puppet cert clean --all + +echo "XCATROOT=$XCATROOT, PUPPETSERVER=$PUPPETSERVER" +if [ -n "$XCATROOT" ]; then + xcatroot=$XCATROOT +else + xcatroot="/opt/xcat" +fi + +#use site.puppetserver or site.master as the puppet server certname +if [ -n "$PUPPETSERVER" ]; then + node=$PUPPETSERVER +else + tmp=`XCATBYPASS=Y $xcatroot/bin/lsdef -t site clustersite 2>&1 |grep "puppetserver="` + if [ $? -eq 0 ]; then + node=`echo $tmp|cut -d= -f2` + fi +fi +if [ -z "$node" ]; then + if [ -n "$SITEMASTER" ]; then + node=$SITEMASTER + else + tmp=`XCATBYPASS=Y $xcatroot/bin/lsdef -t site clustersite 2>&1 |grep "master="` + if [ $? -eq 0 ]; then + node=`echo $tmp|cut -d= -f2` + fi + fi +fi +if [ -z "$node" ]; then + if [ -n "$NODE" ]; then + node=$NODE + else + node=`hostname -s` + fi +fi + +echo "node=$node" + +#configure: we take default for most +confname="/etc/puppet/puppet.conf" +if [ ! -f "$confname" ]; then + cat > $confname << EOT +[main] +logdir=/var/log/puppet +vardir=/var/lib/puppet +ssldir=/var/lib/puppet/ssl +rundir=/var/run/puppet +factpath=$vardir/lib/facter +templatedir=$confdir/templates + +[master] +# These are needed when the puppetmaster is run by passenger +# and can safely be removed if webrick is used. +ssl_client_header = SSL_CLIENT_S_DN +ssl_client_verify_header = SSL_CLIENT_VERIFY +EOT +else + cp -f $confname ${confname}.save +fi + +sed -i "/\[main\]/ a\ + certname = $node" $confname +sed -i "/\[main\]/ a\ + server = $node" $confname + +#create a site manifest site.pp on the master: +cat > /etc/puppet/manifests/site.pp << EOT +node default { + notify { 'I can connect!': } +} +EOT + +#automacally sign the nodes, TODO: add nodes one by one +if [ -n "$DOMAIN" ]; then + domainnames=$DOMAIN +else + tmp=`XCATBYPASS=Y $xcatroot/bin/lsdef -t site clustersite 2>&1 |grep "domain="` + if [ $? -ne 0 ]; then + domainnames="cluster.com" #default + else + domainnames=`echo $tmp| cut -d= -f2` + fi +fi + +confname2="/etc/puppet/autosign.conf" +if [ -f "$confname2" ]; then + cp -f $confname2 ${confname2}.save +fi +echo "*.$domainnames" > $confname2 +echo "*" >> $confname2 #now we have to use this because we use short node name instead of FQDN + +exit 0 + diff --git a/xCAT/postscripts/install_puppet_client b/xCAT/postscripts/install_puppet_client new file mode 100755 index 000000000..be30f15f7 --- /dev/null +++ b/xCAT/postscripts/install_puppet_client @@ -0,0 +1,105 @@ +#!/bin/sh +# IBM(c) 2013 EPL license http://www.eclipse.org/legal/epl-v10.html + + +#------------------------------------------------------------------------------- +#=head1 install_puppet_client +#=head2 This command installs the puppet client on a xCAT node. It is used as +# a postscript on Ubuntu only. +# usage: +# 1. use $PUPPETSERVER or $MASTER as the puppet server +# updatenode -P "install_puppet_client" +# 2. explicitly specify the puppet server +# updatenode -P "install_puppet_client -s puppetservername" +#=cut +#------------------------------------------------------------------------------- + + +#Figure out what os this node has +if [ "$(uname -s)" = "Linux" ]; then + result=`cat /etc/*release* 2>&1` + echo $result|grep "Ubuntu" > /dev/null + if [ $? -eq 0 ]; then + os="Ubuntu" + else + echo $result | grep "Red Hat" > /dev/null + if [ $? -eq 0 ]; then + os="RedHat" + else + echo $result | grep "SUSE" > /dev/null + if [ $? -eq 0 ]; then + os="Sles" + fi + fi + fi +fi + +if [ "$os" == "Ubuntu" ]; then + #cleanup the old installations + echo "Removing old puppet packages....." + apt-get -y autoremove puppet --purge + + #check if the current node is also a puppet master + ismaster=0 + if [ -f /etc/puppet/fileserver.conf ]; then + ismaster=1 + fi + + #clean the all the configuration files if it is not a master + if [ $ismaster -ne 1 ]; then + rm -Rf /etc/puppet/* + rm -Rf /var/lib/puppet/* + fi + + echo "Adding new repositories....." + #get os release name + urelease="precise" #default release name + urelease=`cat /etc/lsb-release |grep DISTRIB_CODENAME |cut -d= -f2` + + #add ubuntu repositories from the net. + #We use us mirror, what about for the customers of other contires? + echo "deb http://us.archive.ubuntu.com/ubuntu/ $urelease main" > /etc/apt/sources.list.d/os_remote.list + echo "deb http://us.archive.ubuntu.com/ubuntu/ ${urelease}-updates main" >> /etc/apt/sources.list.d/os_remote.list + echo "deb http://us.archive.ubuntu.com/ubuntu/ $urelease universe" >> /etc/apt/sources.list.d/os_remote.list + echo "deb http://us.archive.ubuntu.com/ubuntu/ ${urelease}-updates universe" >> /etc/apt/sources.list.d/os_remote.list + + #add the puppet lab repositories + repname=puppetlabs-release-${urelease}.deb + wget -N --waitretry=10 --random-wait -T 60 http://apt.puppetlabs.com/$repname -P /tmp 2>> /tmp/wget.log + rc=$? + if [ $rc -eq 0 ] && [ -f /tmp/$repname ]; then + dpkg -i /tmp/$repname + apt-get update + else + echo "Cannot download http://apt.puppetlabs.com/$repname" + exit 1 + fi + rm /tmp/$repname + + #refresh the repository + apt-get -y update + + echo "Installing puppet client....." + #install puppet client + apt-get -y install puppet + + #configure the puppet agent configuration files + result=`dirname $0` + ${result}/config_puppet_client "$@" + + #puppet agent -t --waitforcert 60& + +elif [ "$os" == "RedHat" ]; then + echo "Puppet client installation with xCAT on RedHat is through a kit. Please refer to ... for details.". +else + echo "Puppet client by xCAT is not supported yet on this plateform." +fi + +exit 0 + + + + + + + diff --git a/xCAT/postscripts/install_puppet_server b/xCAT/postscripts/install_puppet_server new file mode 100755 index 000000000..2db004532 --- /dev/null +++ b/xCAT/postscripts/install_puppet_server @@ -0,0 +1,97 @@ +#!/bin/sh +# IBM(c) 2013 EPL license http://www.eclipse.org/legal/epl-v10.html + + +#------------------------------------------------------------------------------- +#=head1 install_puppet_server +#=head2 This command installs the puppet server on a xCAT server or node. +# It is used on Ubuntu only. +# Usage: +# set $PUPPETSERVER as the puppet server on site table. The default is +# site.master +# install_puppet_server +# or +# updatenode install_puppet_server +#=cut +#------------------------------------------------------------------------------- + +#Figure out what os this node has +if [ "$(uname -s)" = "Linux" ]; then + result=`cat /etc/*release* 2>&1` + echo $result|grep "Ubuntu" > /dev/null + if [ $? -eq 0 ]; then + os="Ubuntu" + else + echo $result | grep "Red Hat" > /dev/null + if [ $? -eq 0 ]; then + os="RedHat" + else + echo $result | grep "SUSE" > /dev/null + if [ $? -eq 0 ]; then + os="Sles" + fi + fi + fi +fi + +if [ "$os" == "Ubuntu" ]; then + #cleanup the old installations + echo "Removing old puppet packages....." + apt-get -y autoremove puppetmaster puppet --purge + rm -Rf /etc/puppet/* + rm -Rf /var/lib/puppet/* + + echo "Adding new repositories....." + #get os release name + urelease="precise" #default release name + urelease=`cat /etc/lsb-release |grep DISTRIB_CODENAME |cut -d= -f2` + + #add ubuntu repositories from the net. + #We use us mirror, what about for the customers of other contires? + echo "deb http://us.archive.ubuntu.com/ubuntu/ $urelease main" > /etc/apt/sources.list.d/os_remote.list + echo "deb http://us.archive.ubuntu.com/ubuntu/ ${urelease}-updates main" >> /etc/apt/sources.list.d/os_remote.list + echo "deb http://us.archive.ubuntu.com/ubuntu/ $urelease universe" >> /etc/apt/sources.list.d/os_remote.list + echo "deb http://us.archive.ubuntu.com/ubuntu/ ${urelease}-updates universe" >> /etc/apt/sources.list.d/os_remote.list + + #add the puppet lab repositories + repname=puppetlabs-release-${urelease}.deb + wget -N --waitretry=10 --random-wait -T 60 http://apt.puppetlabs.com/$repname -P /tmp 2>> /tmp/wget.log + rc=$? + if [ $rc -eq 0 ] && [ -f /tmp/$repname ]; then + dpkg -i /tmp/$repname + apt-get update + else + echo "Cannot download http://apt.puppetlabs.com/$repname" + exit 1 + fi + rm /tmp/$repname + + #refresh the repository + apt-get -y update + + + echo "Installing puppet server....." + #install puppet server + apt-get -y install puppetmaster + + #install rake and git + apt-get -y install rake git + + #Now configure the pupper server + result=`dirname $0` + ${result}/config_puppet_server "$@" + + #restart puppet master + service puppetmaster stop + kill $(ps auxww | grep puppet | grep master | grep -v grep | awk '{print $2}') + service puppetmaster start + +elif [ "$os" == "RedHat" ]; then + echo "Puppet server installation with xCAT on RedHat is through a kit. Please refer to ... for details.". +else + echo "Puppet server setup by xCAT is not supported yet on this plateform." +fi + +exit 0 + +