-
Notifications
You must be signed in to change notification settings - Fork 1
/
taste-test.sh
executable file
·58 lines (52 loc) · 1.84 KB
/
taste-test.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
#!/bin/bash
if [ "$1" = "" ]
then
echo "Usage: taste-test.sh HOSTNAME"
exit
fi
HOSTNAME=$1
DATE=`date +%s`
SESSID="`echo "canary_${USER}_${HOSTNAME/-/_}" | cut -f1 -d"."`_$DATE"
set -e
ssh $HOSTNAME << EOF
wall \$USER is running puppet canary on this host.
echo "[PREFLIGHT] Testing host access..."
EOF
ssh puppet.tech.dreamhack.se echo "[PREFLIGHT] Testing puppet access..."
set +e
read -p "Do you want to canary on $HOSTNAME? [Y/n]" -n 1 -r
if [[ $REPLY =~ ^[Nn]$ ]]
then
echo "Canary aborted!"
else
echo "Putting host $HOSTNAME in canary mode..."
ssh -q -o LogLevel=error $HOSTNAME sudo systemctl stop puppet 2>/dev/null
while true; do
read -p "Push current state and run puppet on $HOSTNAME? [Y/n]" -n 1 -r
if [[ $REPLY =~ ^[Nn]$ ]]
then
echo "Aborting canary!"
break
else
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]
then
echo "Using dirty branch when running canary..."
fi
echo "Pusing current state to puppet.."
rsync -ruvz --exclude=".*" . puppet.tech.dreamhack.se:/etc/puppetlabs/puppet/environments/$SESSID 2>/dev/null
echo "Running puppet on host..."
ssh -q -o LogLevel=error $HOSTNAME "
sudo puppet agent -t --environment $SESSID 2>&1 | tee \$HOME/puppet-canary.log
"
fi
done
fi
echo "Restoring host and puppet server..."
ssh -q -o LogLevel=error puppet.tech.dreamhack.se "
sudo rm -r /etc/puppetlabs/puppet/environments/$SESSID
" 2>/dev/null
ssh -q -o LogLevel=error $HOSTNAME "
wall \$USER is done running puppet canary on this host, going back to production.
sudo systemctl start puppet
" 2>/dev/null
echo "Cleanup done! Dont forget to merge changes on GitHub or they will be overridden on next puppet run."