2019-02-19 17:49:33 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
cat << "EOF"
|
|
|
|
_____ _ _______ _
|
|
|
|
| __ \ | | |__ __| | |
|
|
|
|
| |__) | _ _ __ _ __ ___| |_ | | ___ ___| |_ ___
|
|
|
|
| ___/ | | | '_ \| '_ \ / _ \ __| | |/ _ \/ __| __/ __|
|
|
|
|
| | | |_| | |_) | |_) | __/ |_ | | __/\__ \ |_\__ \
|
|
|
|
|_| \__,_| .__/| .__/ \___|\__| |_|\___||___/\__|___/
|
|
|
|
| | | |
|
|
|
|
|_| |_| by Kris Lamoureux
|
|
|
|
|
|
|
|
Random Puppet tests and projects written for learning
|
|
|
|
https://github.com/krislamo/pup-tests
|
|
|
|
|
|
|
|
To the extent possible under law, Kris Lamoureux has waived
|
|
|
|
all copyright and related or neighboring rights to Puppet
|
|
|
|
Tests. This work is published from the United States.
|
|
|
|
|
|
|
|
You can copy, modify, distribute and perform the work, even
|
|
|
|
for commercial purposes, all without asking permission.
|
|
|
|
|
|
|
|
=============================================================
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
if [ "$1" == "create" ]
|
|
|
|
then
|
2019-03-04 17:14:45 +00:00
|
|
|
|
|
|
|
mkdir -p keys
|
|
|
|
|
|
|
|
if [ -f ./keys/backup-key ] || [ -f ./keys/backup-key.pub ] ; then
|
|
|
|
rm ./keys/backup-key*
|
|
|
|
fi
|
|
|
|
|
|
|
|
ssh-keygen -t rsa -b 4096 -N '' -f ./keys/backup-key
|
|
|
|
|
|
|
|
chmod -R 777 ./keys
|
|
|
|
|
2019-02-19 17:49:33 +00:00
|
|
|
vagrant destroy -f
|
|
|
|
vagrant up
|
|
|
|
|
2020-05-06 00:29:39 +00:00
|
|
|
vagrant ssh master -c "sudo puppet cert sign webserver.localdomain"
|
|
|
|
vagrant ssh master -c "sudo puppet cert sign backups.localdomain"
|
2019-02-19 17:49:33 +00:00
|
|
|
|
|
|
|
vagrant ssh webserver -c "sudo puppet agent -t"
|
|
|
|
vagrant ssh backups -c "sudo puppet agent -t"
|
2019-03-04 17:14:45 +00:00
|
|
|
|
2019-02-19 17:49:33 +00:00
|
|
|
elif [ "$1" == "apply" ]
|
|
|
|
then
|
2019-02-21 16:54:34 +00:00
|
|
|
vagrant ssh master -c "cd /etc/puppet/code/environments/production && \
|
|
|
|
r10k puppetfile install"
|
2019-02-19 17:49:33 +00:00
|
|
|
vagrant rsync
|
|
|
|
if [ -z "$2" ]; then
|
|
|
|
vagrant ssh webserver -c "sudo puppet agent -t"
|
|
|
|
vagrant ssh backups -c "sudo puppet agent -t";
|
|
|
|
else
|
|
|
|
vagrant ssh $2 -c "sudo puppet agent -t";
|
|
|
|
fi
|
2019-03-04 17:14:45 +00:00
|
|
|
|
2019-02-19 17:49:33 +00:00
|
|
|
elif [ "$1" == "cert-update" ]
|
|
|
|
then
|
2020-05-06 00:29:39 +00:00
|
|
|
vagrant ssh master -c "sudo puppet cert clean $2.localdomain"
|
|
|
|
vagrant ssh $2 -c "sudo find /var/lib/puppet/ssl -name $2.localdomain.pem -delete"
|
2019-02-19 17:49:33 +00:00
|
|
|
vagrant ssh $2 -c "sudo puppet agent -t"
|
|
|
|
sleep 3
|
2020-05-06 00:29:39 +00:00
|
|
|
vagrant ssh master -c "sudo puppet cert sign $2.localdomain"
|
2019-02-19 17:49:33 +00:00
|
|
|
sleep 3
|
|
|
|
vagrant ssh $2 -c "sudo puppet agent -t"
|
2019-03-04 17:14:45 +00:00
|
|
|
|
2019-02-19 17:49:33 +00:00
|
|
|
elif [ "$1" == "help" ]
|
|
|
|
then
|
|
|
|
cat << "EOF"
|
|
|
|
Commands
|
|
|
|
|
|
|
|
create creates the environment from the ground up
|
|
|
|
apply syncs code and runs the puppet agent on specified client
|
|
|
|
cert-update update SSL cert
|
|
|
|
help displays this page
|
|
|
|
EOF
|
|
|
|
|
|
|
|
else
|
|
|
|
printf "Error: Command \"$1\" unknown. See \"./pup-tests.sh help\"\n"
|
|
|
|
fi
|
|
|
|
|