1

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?

Ben Smith
  • 157
  • 5

1 Answers1

0

All you can do is wrap the require in a rescue LoadError block, that returns an empty list or whatever a simple, non-error-inducing return value would be. This has to be done inside your function, as the file the function is in will only be loaded once, but the code inside your function will be run every time the function is called.

womble
  • 95,029
  • 29
  • 173
  • 228