Using Puppet instead of Bash

If you’ve done any amount of heavy UNIX systems administration work, you’ve undoubtedly written several big ugly Bash scripts.

#!/bin/bash
for i in `more standard_package_list.txt `
do
apt-get install $i
done

This simple code example will read a txt file with a list of required packages, and then install all packages.

So how can Puppet help us with this task?

#!/usr/bin/puppet

$package_list = ['apache2','php5','screen']

package{$package_list:
ensure => 'latest',
provider => 'apt',
}

Then make sure to chown this file:

$ chmod +x packages.pp
$ ./packages.pp

Now, when you run this file, Puppet will use the built in ‘apt’ package provider to install the list of packages defined at the top of the file.

It’s actually much easier to write a complex script using a high-level language such as Puppet, rather than Bash, despite this example that requires more code to accomplish the same task using Puppet than Bash.

Using Puppet instead of Bash for basic system scripting gives you many advantages such as better debugging, better error handling, standard formatting, better readability, and is generally much easier to perform complicated tasks than Bash or perl.

It also is a great introduction if you’re just getting your feet wet in the Puppet world. Good luck, and check back soon for more Puppet tutorials.

This entry was posted in Code, Linux, Puppet. Bookmark the permalink. Comments are closed, but you can leave a trackback: Trackback URL.
sitemap