-
Notifications
You must be signed in to change notification settings - Fork 35
/
minion-key-reset.sh
executable file
·50 lines (44 loc) · 1.1 KB
/
minion-key-reset.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
#!/bin/bash
#
# do the Salt minion pub/private key stuff
#
#
#set -x
if [ "$1" = "-f" ]; then
CHECK=false
shift
else
CHECK=true
fi
KEY=$1
if $CHECK && [[ ! "$KEY" =~ [0-9A-E]{8}\.[[:alpha:]]+\.[[:alpha:]]+\.pem ]]; then
echo "you need to provide the key as a parameter to this script!"
exit
fi
if [[ ! $(id) =~ ^uid=0 ]]; then
echo "you need to run this as root (e.g. run \"sudo $*\")"
exit
fi
mkdir -p /etc/salt/pki/minion
cp $KEY minion.pem
openssl rsa -in minion.pem -pubout >minion.pub
cp -f minion.pem /etc/salt/pki/minion/minion.pem
cp -f minion.pub /etc/salt/pki/minion/minion.pub
chmod 400 /etc/salt/pki/minion/minion.pem
rm minion.pub minion.pem
#
# write the /etc/salt/minion.d/extra.conf
#
SALT_DOMAIN=$(basename $KEY | cut -d. -f2,3)
SALT_ID=$(basename $KEY | cut -d. -f1)
mkdir -p /etc/salt/minion.d/
cat >/etc/salt/minion.d/extra.conf <<EOF
master: [ salt-master.cisco.com, salt-master-2.cisco.com ]
id: $SALT_ID
append_domain: $SALT_DOMAIN
master_type: failover
verify_master_pubkey_sign: True
master_shuffle: True
master_alive_interval: 180
EOF