Archive for July, 2010

Custom Puppet Facts

Wednesday, July 28th, 2010

I really like the idea of using Puppet and similar tools for automating as much of server configuration as possible. As I slowly “puppet-ify” things I find the need to sometimes add custom facts to facter, the part of Puppet that provides information about the host system.

This would be easy were it not for the small problem that custom facts are written in Ruby, a language I’m not fluent in, although this gives me a reason to learn the basics. I’m familiar with various other languages so it shouldn’t be that hard, here’s what I’ve managed to cobble together so far…

The first fact returns a list of the Linux software RAID block devices on the host. This is just parsing the /proc/mdstat file that should exist on any Linux distribution:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Facter.add('software_raid') do
  confine :kernel => :linux
  setcode do
    devices = []
    if FileTest.exists?('/proc/mdstat')
      File.open('/proc/mdstat', 'r') do |f|
        while line = f.gets
          if line =~ /^(md\d+)/
            devices.push($1)
          end
        end
      end
    end
    devices.sort.join(',')
  end
end

This next recipe creates one fact per bonded network interface on Linux, containing the list of enslaved interfaces. This is specific to CentOS, Fedora, Red Hat or any other similar distributions that use the /etc/sysconfig configuration files:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'find'
 
Facter.value(:interfaces).split(',').each do |interface|
  if interface =~ /^bond\d+$/
    Facter.add("#{interface}_slaves") do
      confine :kernel => :linux, :operatingsystem => %w{CentOS Fedora RedHat}
      setcode do
        slaves = []
        Find.find('/etc/sysconfig/network-scripts') do |path|
          if FileTest.directory?(path)
            next
          else
            if path =~ /ifcfg-(.+)$/
              device = $1
              File.open(path, 'r') do |f|
                while line = f.gets
                  if line =~ /^MASTER\s*=\s*#{interface}$/
                    slaves.push(device)
                  end
                end
              end
            end
          end
        end
        slaves.sort.join(',')
      end
    end
  end
end

I use these two facts within my Puppet manifests as the basis for configuring additional Nagios tests to make sure these two pieces of functionality are working correctly.

Finally Upgraded

Thursday, July 15th, 2010

When did Snow Leopard come out? No, I can’t remember either, but despite upgrading my other lesser-used Intel Mac, I had completely forgotten to do my MacBook Pro which is my main machine these days, I guess I just didn’t have a need to do it, until now.

I’ve had a MobileMe account for a while now which is great for keeping contacts and whatnot synchronised, and I’ve started to dabble with the Back to My Mac feature and I read that Snow Leopard added support for Wake on Demand, including being able to wake supported machines up over the wireless AirPort network in addition to the wired Ethernet. A bit of a google gave mixed results for my model which System Profiler reports as a MacBookPro3,1 (one of the last models before the unibody MacBook Pros) which suggested it was down to the particular make and model of AirPort Extreme card inside, so there was nothing left but to take that final backup and go for it.

Even though I back up to a Time Capsule and Mac OS X in-situ upgrades seem to generally work, I usually prefer to go for a full wipe and reinstall to prevent the build up of any excess cruft over time and then selectively restore anything from the backups by hand.

Once Snow Leopard was installed and updated, I had to reinstall some of my favourite applications, including but not limited to:

  • Shimo – I need to connect to a Cisco VPN for work and this has a far more OS X-y GUI than the standard Cisco horror
  • Growl – amazing just how many OS X apps have support for this notification system
  • RipIt – exactly how DVD ripping should work under OS X
  • Audio Hijack Pro & Fission – using these two I can transfer and encode my vinyl collection to MP3, although I suspect I’m under-utilising Audio Hijack Pro
  • Arduino IDE – for blog cred
  • Last.fm Scrobbler – to update my Last.fm profile
  • Quicksilver – I probably under-utilise this application launcher with bells on
  • ClickToFlash – stop Flash eating my CPU cycles
  • EyeTV – excellent software to record the odd bit of TV worth watching and convert it to play on my iPod

And after all of that, do I have an AirPort Extreme card that supports Wake on Demand? According to this screenshot, it appears not.

System Profiler Screenshot

If I’m really bothered, I could maybe trawl eBay for a newer AirPort Extreme card, although it appears non-trivial to replace so I think I’ll leave it and revisit if/when I get a new Mac. Bugger.