Last active
February 20, 2020 11:48
-
-
Save jtopjian/abf8bfe7b288b004c3b7 to your computer and use it in GitHub Desktop.
Bash script to bootstrap a Puppet Server
This file contains hidden or 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
#!/bin/bash | |
# Set up acng client | |
echo "Acquire::http { Proxy \"http://acng-yyc.cloud.cybera.ca:3142\"; };" > /etc/apt/apt.conf.d/01-acng | |
# Set up proper hostname | |
echo 127.0.1.1 $(hostname).example.com $(hostname) >> /etc/hosts | |
# Installing curl and wget | |
apt-get update | |
apt-get install -y curl wget | |
cd /root | |
wget https://apt.puppetlabs.com/puppetlabs-release-trusty.deb | |
dpkg -i puppetlabs-release-trusty.deb | |
rm puppetlabs-release-trusty.deb | |
apt-get update | |
echo "Installing Puppet, Rake, Ruby 1.9" | |
apt-get install -y git rake ruby puppet | |
mkdir -p /etc/facter/facts.d | |
# Not really needed. But kept for notes | |
#echo "Installing and configuring Java 8" | |
#add-apt-repository -y ppa:webupd8team/java | |
#echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections | |
#apt-get install -y oracle-java8-installer | |
echo "Initial changes to puppet.conf" | |
sed -i '/templatedir/d' /etc/puppet/puppet.conf | |
puppet config set --section main parser future | |
puppet config set --section main evaluator current | |
puppet config set --section main ordering manifest | |
echo "Starting Puppet Master to generate certs" | |
puppet master --verbose | |
sleep 5 | |
echo "Killing Puppet Master" | |
pkill -9 puppet | |
echo "Installing PuppetDB" | |
cd /etc/puppet/modules | |
puppet module install puppetlabs/puppetdb | |
cd /root | |
echo include puppetdb > pdb.pp | |
echo include puppetdb::master::config >> pdb.pp | |
puppet apply --verbose pdb.pp | |
sleep 5 | |
puppet apply --verbose pdb.pp | |
rm -rf /etc/puppet/modules/* | |
rm /root/pdb.pp | |
echo "Setting up Directory Environments" | |
PROD="/etc/puppet/environments/production" | |
SITE="${PROD}/local/site" | |
puppet config set --section main environmentpath \$confdir/environments | |
mkdir -p $PROD/{modules,local,manifests} | |
mkdir -p $SITE/{files,templates,manifests,ext,data} | |
mkdir $SITE/manifests/{roles,profiles} | |
echo modulepath = modules:local > $PROD/environment.conf | |
mv /etc/puppet/puppet.conf $SITE/ext | |
ln -s $SITE/ext/puppet.conf /etc/puppet/ | |
echo "Installing r10k" | |
gem install deep_merge | |
gem install r10k | |
echo "Configuring Hiera" | |
cat > $SITE/ext/hiera.yaml <<EOF | |
--- | |
:backends: | |
- yaml | |
:hierarchy: | |
- "nodes/%{::fqdn}" | |
- "osfamily/%{::osfamily}" | |
- "locations/%{::location}" | |
- "common" | |
:yaml: | |
:datadir: "/etc/puppet/environments/%{::environment}/local/site/data" | |
EOF | |
mkdir $SITE/data/nodes | |
mkdir $SITE/data/locations | |
ln -s $SITE/ext/hiera.yaml /etc/puppet | |
rm /etc/hiera.yaml | |
ln -s $SITE/ext/hiera.yaml /etc/ | |
echo "Creating a standard Puppetfile" | |
cat > $SITE/ext/Puppetfile <<EOF | |
forge 'http://forge.puppetlabs.com' | |
mod 'apache', | |
:git => 'https://github.com/puppetlabs/puppetlabs-apache' | |
mod 'apt', | |
:git => 'https://github.com/puppetlabs/puppetlabs-apt', | |
:ref => '1.5.0' | |
mod 'vcsrepo', | |
:git => 'https://github.com/puppetlabs/puppetlabs-vcsrepo', | |
:ref => '1.0.0' | |
mod 'concat', | |
:git => 'https://github.com/puppetlabs/puppetlabs-concat', | |
:ref => '1.1.0' | |
mod 'ntp', | |
:git => 'https://github.com/puppetlabs/puppetlabs-ntp', | |
:ref => '3.1.0' | |
mod 'puppetdb', | |
:git => 'https://github.com/puppetlabs/puppetlabs-puppetdb', | |
:ref => '3.0.1' | |
mod 'postgresql', | |
:git => 'https://github.com/puppetlabs/puppetlabs-postgresql', | |
:ref => '3.3.3' | |
mod 'stdlib', | |
:git => 'https://github.com/puppetlabs/puppetlabs-stdlib', | |
:ref => '4.2.2' | |
mod 'inifile', | |
:git => 'https://github.com/puppetlabs/puppetlabs-inifile', | |
:ref => '1.0.4' | |
mod 'puppet', | |
:git => 'https://github.com/jtopjian/puppet-puppet' | |
EOF | |
ln -s $SITE/ext/Puppetfile $PROD | |
echo "Running r10k on the Puppetfile" | |
cd $PROD | |
r10k puppetfile install | |
echo "Configuring the Puppet Master" | |
cat > $SITE/manifests/roles/base.pp <<EOF | |
class site::roles::base { | |
} | |
EOF | |
mkdir -p $SITE/manifests/roles/puppet | |
cat > $SITE/manifests/roles/puppet/master.pp <<EOF | |
class site::roles::puppet::master { | |
include ::apache | |
include ::apache::mod::ssl | |
include ::apache::mod::passenger | |
include ::puppet | |
include ::puppet::master | |
include ::puppetdb | |
include ::puppetdb::master::config | |
} | |
EOF | |
fqdn=$(facter fqdn) | |
cat > $SITE/data/common.yaml <<EOF | |
puppet::settings: | |
server: '${fqdn}' | |
environmentpath: '\$confdir/environments' | |
parser: 'future' | |
evaluator: 'current' | |
ordering: 'manifest' | |
pluginsync: true | |
logdir: '/var/log/puppet' | |
vardir: '/var/lib/puppet' | |
ssldir: '/var/lib/puppet/ssl' | |
rundir: '/var/run/puppet' | |
puppet::agent::settings: | |
certname: "%{::fqdn}" | |
show_diff: true | |
splay: false | |
configtimeout: 360 | |
usecacheonfailure: true | |
report: true | |
environment: "%{::environment}" | |
EOF | |
cat > $SITE/data/nodes/${fqdn}.yaml <<EOF | |
puppet::master::servertype: 'passenger' | |
puppet::master::settings: | |
ca: true | |
EOF | |
cat > $SITE/ext/site.pp <<EOF | |
node base { | |
include site::roles::base | |
} | |
node '${fqdn}' inherits base { | |
include site::roles::puppet::master | |
} | |
EOF | |
ln -s $SITE/ext/site.pp $PROD/manifests/ | |
puppet apply --verbose /etc/puppet/environments/production/manifests/site.pp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment