Monday, 11 August 2014

Quick and dirty hacking hosts.equiv with xcat

I've mentioned before that we use xCAT for auto discovery and genesis of nodes in our environment, we've recently had need to add a second domain for a separate cluster of systems. We need to be able to ssh without keys around those systems, which is pretty simple using hosts.equiv, though we need it to be updated regularly as we add nodes to the system, so a quick and dirty shell script is called for called from cron every day to dump all the nodes in the relevant group. The script dumps the output into a directory which is in the synclists for the xcat profile so it gets pushed to new nodes on initial install and xdcp copies it out to the nodes each day.

Oh and there's a quick catch to make sure the file looks vaguely sane before distributing it, just in case something bad happens with the nodels...

#!/bin/bash

PATH=/sbin:/bin:/usr/bin:/usr/sbin:/opt/xcat/bin
GROUP=foo
OUTPUT=/install/data/$GROUP/etc/hosts.equiv
DOMAIN=baa.cluster
MASTER=xcatmaster
date=`date`

cat <<- EOT > $OUTPUT
# autogenerated
# on $date
$MASTER
$MASTER.main.cluster
$MASTER-foo
$MASTER-foo.$DOMAIN
EOT

for node in `nodels $GROUP`; do
  cat <<- EOT >> $OUTPUT
$node
$node.$DOMAIN
EOT
done
WC=`wc -l $OUTPUT | awk '{print $1}'` 

if [ $WC -lt 12 ]; then
  echo "WARNING: Unexpcted number of lines in $OUTPUT"
else
  xdcp $GROUP -Q $OUTPUT /etc/hosts.equiv

fi

No comments:

Post a Comment