Emergency-stop

Written by Ger Apeldoorn. Posted in Sysadmin

When upgrading the Puppet master (or messing things up) it can be useful to have a quick script that enables the firewall and stops incoming connections.

This is a simple script that enables that. Note that it assumes that the normal situation does not have any firewall-rules running.

/usr/local/bin/puppetstop:

/etc/sysconfig/iptables-emergencystop:

/usr/local/bin/puppetstopundo:

/usr/local/bin/puppetenable

MPI – Managing multiple customers within a single environment

Written by Ger Apeldoorn. Posted in Manageable Puppet Infrastructure

Intro

This is set in the Manageable Puppet Infrastructure, but should be quite useable if you’re not using it.

You want to manage multiple clients within a single environment. (You probably don’t want to create seperate environments or puppetmasters, because that creates quite a bit of overhead in the long run).

But how do we keep things flexible? It’s quite simple, use Hiera and classes in a smart way and you’re there!

One note; this simple setup only works if you do not have any naming conflicts in the modules. e.g. customer1 needs puppetlabs/apache and another needs another module named apache. In that case, you do need seperate environments.

Get that $customer variable filled

You’ll need a way to let Puppet know what customer a node belongs to. There are several ways:

Facter variables can be overridden quite easily. Use the ENC or Hiera!

  • Getting the info from Hiera, see below.
  • Set it from the ENC.

Adding a global $customer variable

In my site.pp:

Example: hieradata/hosts/myserver.customer.com.yaml

That’s an easy way to get the $customer (global) variable filled!

Putting it to use!

Roles

With the MPI, you’ve created a baserole that applies to all hosts.

We can still use that, just be aware that those resources/includes apply to ALL customers.

Also, we’d like a baseclass for each customer. Within the roles-module, that’s a piece of cake.

Hiera

You can add a level for customer-specific settings.

Now, we can add a yaml file for each customer and assign the role::customer::base there.

Example: hieradata/customer/mycustomer1.yaml

Of course, you can add other customer-specific settings as well here!

Feedback is welcome, leave a message!

Script to generate certificates & Puppet-code

Written by Ger Apeldoorn. Posted in Sysadmin

My laziness knows no bounds, I use the script below to automate writing automation puppet code for creating new users (and generating, converting and mailing their certificates too)…

This ruby script will read information from a CSV-file and:

  • generate certificate with a random passphrase
  • create a Putty version
  • email the (encrypted) certificates to the user
  • prints the Puppet-resource definition to STDOUT
  • store the passphrase in a textfile

It will check if the certificates have already been generated (check if directory exists), so you can just add to the CSV-file.

Installing

Prerequisites:

  • Ruby of course
  • some rubygems: mail, csv
  • pwgen
  • ssh-keygen
  • puttygen

Just put the files below in the same directory.

Usage

Edit the userlist.txt to add users; the format is:

userid,username,name,email,groups (groups ; seperated)

Example:

After that’s done, just run the script:

Example output:

After running this, the user receives an email with mailtext.txt as contents and three attachments:

  • id_rsa
  • id_rsa.pub
  • putty_private.ppk

Note that the private keys are protected with the passphrase… 🙂

Files

gencerts.rb:

mailtext.txt:

Have fun!

Betere versienummers bij Puppet runs

Written by Ger Apeldoorn. Posted in Sysadmin

Bij elke Puppetrun wordt er een configuratieversie getoont, dit is een nummer gebaseerd op datum/tijd.

Voorbeeld:

Aangezien wij onze manifests en hiera-data met Git beheren (en die met tags uitrollen) kunnen we daar natuurlijk beter iets aan koppelen waar we wat aan hebben:

Zoals je hierboven kunt zien is het versienummer uit 3 componenten opgebouwd:

  • Tag Manifests
  • Tag Hieradata
  • Environment

Daar heb je tenminste wat aan!

Om dit voorelkaar te krijgen, moeten we een paar handelingen verrichten:

  • Script plaatsen
  • Configuratie Puppet Master aanpassen
  • Puppet Master restarten

Script

Maak een scriptje aan (/etc/puppetlabs/puppet/version.sh) met de volgende inhoud:

Maak hem executable:

Configuratie Puppet Master

Voeg aan /etc/puppetlabs/puppet/puppet.conf het volgende regeltje toe onder [main].

Restart Puppet Master

Als laatste restarten we nog even de PUppet Master om de configuratiewijziging te activeren: