Search code examples
puppet

Adding parameters to custom provider in puppet


I've forked one of the existing package providers (appdmg.rb) to use in my module. I simply want to ask an extra parameter "path" as a custom installation target path. I use @resource[:path] in the modified module and I've put it in /lib subdirectory. After restarting puppet master, it is recognised and synchronised to agent properly - I've checked it's availability in /var/lib/puppet/ on the agent, but I get a parameter error during test run:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid parameter path at /etc/puppet/modules/xcode/manifests/init.pp:6 on node lon02-mac-09.local

The manifest code is:

package {
  "xcode-${version}" :
    provider => 'appdmg2',
    source   => "/storage/xcode-${version}.dmg",
    path     => "/Applications/Xcode${version}.app",
}

Is there anything special I have to do to make it working?


Solution

  • It's not quite that simple. The provider serves as the backend for a type. To enable Puppet to use an additional parameter to the package type, you will have to add it to the respective type code such as the source param in the upstream code.

    Once you patch that in, @resource[:path] should indeed work inside the provider instances.

    Of course, such additions are not suitable for a module, so you would techically need to actually add a new type of your own (and sadly, there is no subtyping yet).

    It may be worth checking wether install_options can perhaps solve your problem using the existing provider.