Loading dependencies for custom puppet functions
- by Ben Smith
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?