Recently, I felt in love with Homebrew as it is far better way to manage apps then Fink and Ports I used before.
I want to manage my Homebrew apps with Puppet and this is how I’m doing it.
Some research before coding and found this Homebrew module on github.
Install module wherever you want (depends on setup type – are you standalone or client/server driven?) and we are going to configure it.
I renamed module to osx-homebrew as I want every OS X specific modules visible by simple ls. So, where I type osx-homebrew you will have plain homebrew.
I have now for testing one Puppet master in virtual machine (this workflow will change soon) thus I installed module to $puppet_dir/modules on my master.
In node definition file (in my case only site.pp for now) configuration looks like this:
node 'hack-pro' { class { 'osx-homebrew': user => 'jozef', } $pkglist = ['detox', 'nmap', 'git'] package { $pkglist: ensure => installed, provider => brew, require => Class['osx-homebrew'] } }
After test run I found one error:
Error: Could not prefetch package provider 'brew': Could not list packages: Execution of '/usr/local/bin/brew list --versions' returned 1: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:853:in `expand_path': couldn't find HOME environment -- expanding `~/Library/Caches/Homebrew' (ArgumentError) from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:853:in `expand_path' from /usr/local/Library/Homebrew/global.rb:22:in `cache' from /usr/local/Library/Homebrew/global.rb:41 from /usr/local/Library/brew.rb:18:in `require' from /usr/local/Library/brew.rb:18
Unfortunately this error comes from changes in Puppet 3.X – there was introduced change where Puppet stripes $HOME variable.
You can find hotfix here.
Download it on Puppet master (in my case, find your own install path) to:
wget https://raw.github.com/nanliu/puppet-homebrew/89e5eb7408b13a87f2d229e3b023deca835201d8/lib/puppet/provider/package/homebrew.rb -O ./modules/osx-homebrew/lib/puppet/provider/package/homebrew.rb
In next run on Puppet client you will spot this:
[jozef @ hack-pro ~]$ puppet agent -t Info: Retrieving plugin Info: Loading facts in /Users/jozef/.puppet/var/lib/facter/has_compiler.rb Info: Caching catalog for prg1 Info: Applying configuration version '1361584588' Notice: /Stage[main]//Node[prg1]/Package[git]/ensure: created Notice: /Stage[main]//Node[prg1]/Package[nmap]/ensure: created
Win!
One warning: this approach assumes you have compiler installed. If you are compiler-free you can install it with osx-homebrew module:
class { 'homebrew': command_line_tools_package => 'command_line_tools_for_xcode_os_x_lion_aug_2012.dmg', command_line_tools_source => 'http://puppet/command_line_tools_for_xcode_os_x_lion_aug_2012', }
You should notice that you must have command line tools pre-downloaded as Apple requires Apple ID to download them.
Automation of DMG files install and download security will be covered in some of next posts, for now you are on your own. :)