Trying to work around [being unable to specify the alternative path to `gem`](https://ask.puppet.com/question/27044/how-to-install-gems-for-non-default-ruby-with-puppet/), I decided to implement my own package-provider, which would allow users to specify the path to the command as a separate parameter. My usage would be something like:
package {'sensu':
ensure => installed,
provider => 'mygem',
command => '/usr/local/bin/gem22'
}
My plan was to inherit my new provider-class from the existing gem-class and overwrite the `:gemcmd` in it with the value supplied by the manifest. I declare the new provider thus:
Puppet::Type.type(:package).provide :mygem, :parent => :gem, :source => :gem do
desc "Ruby Gem support with the ability to specify an alternative
gem-command. For example: command => '/usr/local/bin/gem22'"
.....
I then successfully (?) added the new parameter to all package-providers:
Puppet::Type.type(:package).newparam(:command) do
desc "Specify alternative package-command such as
'/usr/local/bin/gem22'"
end
and the sample manifest quoted above is no longer triggering Puppet errors. However, the methods inside my new provider do not get the value of the `command`-attribute, whatever I try. The `@resource` is not set, for example, and I can't figure out, how to access the new value. For example, trying to overwrite the gem's `self.instances` method:
def self.instances(justme = false)
puts "==> In instances"
commands :gemcmd => @resource[:command]
super
end
I get an error about `@resource` being nil:
....
==> In instances
Error: Could not prefetch package provider 'mygem': undefined method `[]' for nil:NilClass
....
How can the `self.prefetch` method, for example, get access to the attributes specified in the manifest? Thanks!
↧