Loading dependencies for custom puppet functions

Posted by Ben Smith on Server Fault See other posts from Server Fault or by Ben Smith
Published on 2012-04-05T08:53:45Z Indexed on 2012/04/05 11:32 UTC
Read the original article Hit count: 322

Filed under:
|
|

I have written a custom puppet function, which is working fine, that depends on the cloudservers gem (a Rackspace client library). This is fine if I have pre-installed the gem on a server before running puppet but totally breaks if I have not installed the gem as the function seems to be run during the 'compilation' sweep, well before my package definition is realised. Here's what my .pp looks like, with get_hosts the function that requires the cloudservers gem.

package { "rubygems":
    ensure   => installed,
    provider => "gem";
}

package { "cloudservers":
    ensure   => installed,
    provider => "gem",
    require  => Package["rubygems"];
}

class hosts::us {

    $hosts = get_hosts("us")

    hostentry { $hosts: }
}

define hostentry() {
  $parts   = split($name, ',')
  $address = $parts[0]
  $ip      = $parts[1]
  $aliases = $parts[2]
  host{ $address: ip => $ip, host_aliases => $aliases }
}

Is there a way to stop the function getting run so early, or at least having it's run depend up the library being installed. Alternatively, is there a way that I can add dependencies somewhere in the functions folder that will be available to the function?

© Server Fault or respective owner

Related posts about puppet

Related posts about ruby