Created
August 13, 2015 21:31
-
-
Save devshorts/e3d89b4e5dce9f145439 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
ENVIRONMENT=develop | |
MACHINE=$1 | |
shift | |
function print_help(){ | |
echo " | |
Usage: | |
<puppet-agent-host> | |
-role <role> | |
-master <puppet-master-host> | |
-env <env>" | |
} | |
while [ $# -gt 0 ]; | |
do | |
case $1 in | |
-role) | |
shift | |
ROLE=$1 | |
shift | |
;; | |
-master) | |
shift | |
MASTER=$1 | |
shift | |
;; | |
-env) | |
shift | |
ENVIRONMENT=$1 | |
shift | |
;; | |
*) | |
print_help | |
exit 1; | |
;; | |
esac | |
done | |
if [[ "$MACHINE" == "" || "$MASTER" == "" ]]; then | |
print_help | |
exit 1 | |
fi | |
function execute_remote () { | |
if [ $# != 2 ] | |
then | |
echo "Usage: execute-remote <host> <file>" | |
return 1 | |
fi | |
machine=$1 | |
sourcefile=$2 | |
echo "Will execute root commands (in $sourcefile) on the remote ($machine)! Continue?" | |
read | |
COMMAND=`base64 -i $sourcefile` | |
ssh -tt $machine "echo $COMMAND | base64 -d | sudo bash" | |
} | |
read -d '' CONF << EOF | |
[main] | |
# The Puppet log directory. | |
# The default value is '\$vardir/log'. | |
logdir = /var/log/puppet | |
# Where Puppet PID files are kept. | |
# The default value is '\$vardir/run'. | |
rundir = /var/run/puppet | |
# Where SSL certificates are kept. | |
# The default value is '\$confdir/ssl'. | |
ssldir = \$vardir/ssl | |
pluginsync = true | |
[agent] | |
# The file in which puppetd stores a list of the classes | |
# associated with the retrieved configuratiion. Can be loaded in | |
# the separate ``puppet`` executable using the ``--loadclasses`` | |
# option. | |
# The default value is '\$confdir/classes.txt'. | |
classfile = \$vardir/classes.txt | |
# Where puppetd caches the local configuration. An | |
# extension indicating the cache format is added automatically. | |
# The default value is '\$confdir/localconfig'. | |
localconfig = \$vardir/localconfig | |
server = ${MASTER} | |
environment = ${ENVIRONMENT} | |
runinterval = 60 | |
stringify_facts = false | |
EOF | |
echo "$CONF" > /tmp/puppet-agent.conf | |
echo """ | |
echo \"`whoami` ALL=(ALL) NOPASSWD:ALL\" > /etc/sudoers.d/z`whoami`-user | |
yum -y remove puppet | |
rm -rf /etc/puppet/* | |
rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm | |
yum -y install puppet | |
mkdir -p /etc/.config | |
echo $ROLE > /etc/.config/role | |
cp /home/`whoami`/puppet-agent.conf /etc/puppet/puppet.conf | |
puppet resource service puppet ensure=running enable=true | |
""" > /tmp/puppet-agent-bootstrap.sh | |
scp /tmp/puppet-agent.conf $MACHINE:/home/`whoami`/puppet-agent.conf | |
execute_remote $MACHINE /tmp/puppet-agent-bootstrap.sh | |
echo "OK" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bootstraps a puppet agent