This is a repackaging of tutorials offered by
/etc/hosts
Make sure that both machines can resolve puppet to the master
Add puppetlabs apt repo to systems
On local machine
hosts=('master' 'agent') for host in ${hosts[@]} do ssh root@$host "wget https://apt.puppetlabs.com/puppetlabs-release-precise.deb" ssh root@$host "dpkg -i puppetlabs-release-precise.deb" ssh root@$host "apt-get update" done
On master, install puppet master
apt-get install -y puppetmaster-passenger
On master, stop apache
service apache2 stop
On agent, install puppet
apt-get install -y puppet
On master, comment out the templatedir directive in the main section of puppet.conf
sed -i s/^templatedir/#templatedir/ /etc/puppet/puppet.conf
On master, create CA
puppet master --verbose --no-daemonize
NOTE: Kill this process after the following is displayed:
Notice: Starting Puppet master version <VERSION>
On master, start apache
service apache2 start
On agent, comment out the templatedir directive in the main section of puppet.conf
sed -i s/^templatedir/#templatedir/ /etc/puppet/puppet.conf
On agent, run agent to generate cert
puppet agent -t
On master, sign agent cert
puppet cert sign --all
On agent, run agent to get catalog
puppet agent -t
apt-get install -y git git config --global user.email "test@example.com" git config --global user.name "test user"
On master, install r10k modules and dependencies
puppet module install zack/r10k
On master, install and configure r10k using module
cat > configure_r10k.pp <<EOD class { 'r10k': version => '1.3.2', sources => { 'puppet' => { 'remote' => 'file:///root/puppet-repo/git/controller.git', 'basedir' => "\${::settings::confdir}/environments", 'prefix' => false, } }, purgedirs => ["\${::settings::confdir}/environments"], manage_modulepath => false, } EOD puppet apply configure_r10k.pp
On master, add directives to main section of puppet.conf
[main] .... environmentpath = $confdir/environments basemodulepath = $confdir/modules
On master, but in the real world this would be on a development system
mkdir -p puppet-repo/src puppet-repo/git cd puppet-repo/git git init --bare controller.git
On master, but in the real world this would be on a development system
git init --bare helloworld.git
On master, but in the real world this would be on a development system
cd ../src git clone ../git/helloworld.git cd helloworld puppet module generate testing/helloworld --skip-interview mv testing-helloworld/* . rm -rf testing-helloworld cat > manifests/init.pp <<EOD class helloworld { notify { "Hello world!": message => "I am in the \${environment} environment", } } EOD git add --all git commit -m "Add helloworld module" git push -u origin master
On master, but in the real world this would be on a development system
cd .. git clone ../git/controller.git cd controller
In git checkout of controller ...
cat > environment.conf <<EOD modulepath = modules:\$basemodulepath EOD git add environment.conf git commit -m "Add environment.conf" git branch -m production git push -u origin production
mkdir manifests cd manifests cat > site.pp <<EOD node default { include helloworld } EOD cd ../ git add manifests git commit -m "Add helloworld module to default node" git push
cat > Puppetfile <<EOD mod "helloworld", :git => "file:///root/puppet-repo/git/helloworld.git" EOD git add Puppetfile git commit -m "Add Puppetfile to r10k controller" git push
In git checkout of controller ...
tree ../controller ../controller/ ├── environment.conf ├── manifests │ └── site.pp └── Puppetfile
On master, run r10k to deploy production environment
r10k deploy environment -p -v service apache2 restart
You should now have the helloworld module associated with the production environment on the system.
On master, inspect helloworld in production environment
cat /etc/puppet/environments/production/modules/helloworld/manifests/init.pp
Applying the production environment on the agent should result in the hello world message notifying you that it is classified to the production environment.
On agent, run agent to get catalog
puppet agent -t
Manually deploying is something git can automate for us.
Create a post-update hook to do this for us
cat >> ../../git/controller.git/hooks/post-update <<EOD #!/bin/sh r10k deploy environment -p -v && service apache2 restart EOD chmod +x ../../git/controller.git/hooks/post-update
On master, but in the real world this would be on a development system
In git checkout of controller ...
git checkout -b testing git push -u origin testing
You should now have the helloworld module associated with the testing environment on the system.
On master, inspect helloworld in testing environment
cat /etc/puppet/environments/testing/modules/helloworld/manifests/init.pp
On agent, add the following section to the puppet.conf
[agent] environment = testing
On agent, run agent to get catalog
puppet agent -t
We will now add an module to the Puppetfile in the testing branch.
On master, but in the real world this would be on a development system
In git checkout of controller ...
cat >> Puppetfile <<EOD mod "puppetlabs/motd" EOD git add Puppetfile git commit -m "Add motd to testing env" git push
The motd module is now installed in the testing environment on the system, but not in the production environment.
On master, inspect the modules installed for both the production and testing environments.
ls /etc/puppet/environments/testing/modules ls /etc/puppet/environments/production/modules
We will now destroy the testing environment by deleting the testing branch.
On master, but in the real world this would be on a development system
In git checkout of controller ...
git checkout production git branch -D testing git push origin --delete testing
The testing environment is now history.
On master, inspect the environments installed on the master
ls /etc/puppet/environments