Jozef Mares – Page 11 – jozefmares.com
Home Author
Author

Jozef Mares

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. :)

Previous posthave covered basic Puppet install. Now it is time to move to first module.

I created very basic module which will use appdmg provider. This is good to remember as on OS X this is standard packaging method of software distribution. To be honest, it is not very elegant nor efficient as Linux RPM or DEB packaging methods – but it is all I have. :)

Unfortunately as there are no repositories (yes, I know about ports, homebrew) and so on but there are not used to distribute software like VMWare, Firefox etc. Enough bullshit, let’s see some code!

class osx-firefox {

package { 'Firefox':
provider  => appdmg,
source    => "http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/latest/mac/en-US/Firefox%2019.0.dmg",
ensure    => installed,
}

}

You can see I named module osx-firefox as I have every app as separate module. Why is this useful? If I want to include for example package osx-vmware to node “hack-pro” but not to “macbook-air” node I can with simple:

include osx-vmware

This code is stored in file init.pp which is in $module_path/osx-firefox/manifests/init.pp

You can do test run by removing Firefox and running (this, with –noop option is simple method to test modules):

puppet apply path_to_init.pp

Hooray, my first module works like a charm and installed Firefox for me.

Puppet is cool automation and configuration management tool. I’m really happy with it since day I discovered it – and there is not so much tools that are that useful.

I have puppetized all kind of tasks on my servers like user management, service installation and configuration but on desktop there was nothing puppetized and automated. It’s time to change it.

I’m going to cover installation only in this post, next posts will cover application management, plist management and I hope I will find a way how to interact with keychain.

Installation is pretty simple compared to older days. :) Just visit Puppet labs download page and install latest versions of Puppet, Hiera and Facter.

You should install Facter first as Puppet need it.

Next step is to create group and user by running:

sudo puppet resource group puppet ensure=present
sudo puppet resource user puppet ensure=present gid=puppet shell='/sbin/nologin'

If you want puppet to run in master/client setup add these plist files to your system. They will ensure that Puppet master and Puppet itself will start-up during boot:

wget http://docs.puppetlabs.com/guides/files/com.puppetlabs.puppetmaster.plist
wget http://docs.puppetlabs.com/guides/files/com.puppetlabs.puppet.plist

Move plists to /Library/LaunchDaemons, set rights and let launchd let know about them:

sudo chown root:wheel /Library/LaunchDaemons/com.puppetlabs.puppet.plist
sudo chmod 644 /Library/LaunchDaemons/com.puppetlabs.puppet.plist
sudo chown root:wheel /Library/LaunchDaemons/com.puppetlabs.puppetmaster.plist
sudo chmod 644 /Library/LaunchDaemons/com.puppetlabs.puppetmaster.plist

sudo launchctl load -w /Library/LaunchDaemons/com.puppetlabs.puppet.plist
sudo launchctl load -w /Library/LaunchDaemons/com.puppetlabs.puppetmaster.plist

You should also let know system where Puppet master is, for this basic setup you can just add this to your /etc/hosts:

127.0.0.1 puppet

For OS X I prefer standalone setup, but this will be covered in next post.