forked from MariusCC/chef-bcpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster-enroll-cobbler.sh
executable file
·82 lines (75 loc) · 2.45 KB
/
cluster-enroll-cobbler.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
#!/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" ]]; then
echo "Usage: $0 add|remove (hostname)"
exit
fi
if [[ ! -z "$2" ]]; then
EXACTHOST=$2
fi
TRANSCRIPT="cobbler-transcript.txt"
if [[ -f $TRANSCRIPT ]]; then
touch $TRANSCRIPT
fi
if [[ -f cluster.txt ]]; then
echo "Using cluster definition from cluster.txt"
while read HOSTNAME MACADDR IPADDR ILOIPADDR DOMAIN ROLE; do
if [[ $HOSTNAME = "end" ]]; then
continue
fi
if [[ "$ROLE" = "bootstrap" ]]; then
# let's not try to cobbler boot ourselves
continue
fi
if [[ $1 = add ]];then
if [[ -z "$EXACTHOST" || "$EXACTHOST" = "$HOSTNAME" || "$EXACTHOST" = "$ROLE" ]]; then
MATCH="$HOSTNAME"
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
fi
elif [[ $1 == remove ]]; then
if [[ -z "$EXACTHOST" || "$EXACTHOST" = "$HOSTNAME" || "$EXACTHOST" = "$ROLE" ]]; then
MATCH="$HOSTNAME"
ACTIONSTRING="removing $HOSTNAME from cobbler..."
echo $ACTIONSTRING | tee -a $TRANSCRIPT
sudo cobbler system remove --name=$HOSTNAME
fi
else
echo "Usage: \"$1\" unrecognized"
exit
fi
done < cluster.txt
else
echo "Error: No cluster definition (cluster.txt) available"
exit
fi
if [[ ! -z "$MATCH" ]]; then
# made at least one change to cobbler config
echo "Cobbler sync..."
sudo cobbler sync
else
if [[ -z "$EXACTHOST" ]]; then
echo No hosts defined, no action taken.
else
echo Error : Host "'$2'" unrecognized, no action taken.
fi
fi