#!/bin/bash # A script to enroll cluster nodes in cobbler based on a cluster # definition in cluster.txt : # # - If a node is provided, that node will be addded or removed depending # on the first parameter # # - if no node is provided, the first parameter will be used to choose # an action to apply to all nodes # # - if a special nodename is provided that matches a role, then all # hosts with that role will have the specified cobbler action (add # or remove) applied to them. [Technically cobbler doesn't know # anything about roles, however it can be convenient to register, # say, all head nodes first, get them up and running without any # risk of work nodes accidentally coming up before they have a head # node to talk to, and then register all work nodes later.] # # If any cobbler registrations were changed, cobbler sync is called # if [[ -z "$1" ]] { echo "Usage: $0 add|remove (hostname)" exit } if [[ ! -z "$2" ]] { setglobal EXACTHOST = $2 } setglobal TRANSCRIPT = '"cobbler-transcript.txt'" if [[ -f $TRANSCRIPT ]] { touch $TRANSCRIPT } if [[ -f cluster.txt ]] { echo "Using cluster definition from cluster.txt" while read HOSTNAME MACADDR IPADDR ILOIPADDR DOMAIN ROLE { if [[ $HOSTNAME = "end" ]] { continue } if [[ "$ROLE" = "bootstrap" ]] { # let's not try to cobbler boot ourselves continue } if [[ $1 = add ]]{ if [[ -z "$EXACTHOST" || "$EXACTHOST" = "$HOSTNAME" || "$EXACTHOST" = "$ROLE" ]] { setglobal MATCH = $HOSTNAME setglobal ACTIONSTRING = ""adding $HOSTNAME.$DOMAIN ($IPADDR,$MACADDR) to cobbler..."" echo $ACTIONSTRING | tee -a $TRANSCRIPT sudo cobbler system add --name=$HOSTNAME --hostname=$HOSTNAME.$DOMAIN --profile=bcpc_host --ip-address=$IPADDR --mac=$MACADDR --interface=eth0 } } elif [[ $1 == remove ]] { if [[ -z "$EXACTHOST" || "$EXACTHOST" = "$HOSTNAME" || "$EXACTHOST" = "$ROLE" ]] { setglobal MATCH = $HOSTNAME setglobal ACTIONSTRING = ""removing $HOSTNAME from cobbler..."" echo $ACTIONSTRING | tee -a $TRANSCRIPT sudo cobbler system remove --name=$HOSTNAME } } else { echo "Usage: \"$1\" unrecognized" exit } } < cluster.txt } else { echo "Error: No cluster definition (cluster.txt) available" exit } if [[ ! -z "$MATCH" ]] { # made at least one change to cobbler config echo "Cobbler sync..." sudo cobbler sync } else { if [[ -z "$EXACTHOST" ]] { echo No hosts defined, no action taken. } else { echo Error : Host "'$2'" unrecognized, no action taken. } }