Skip to content

Instantly share code, notes, and snippets.

@asasfu
Created October 1, 2015 17:13
Show Gist options
  • Save asasfu/e00eaf76f37141fca083 to your computer and use it in GitHub Desktop.
Save asasfu/e00eaf76f37141fca083 to your computer and use it in GitHub Desktop.
A way to better support service_provider_fact
module Puppet::Parser::Functions
newfunction(:service_provider_func, :type => :rvalue, :doc => <<-EOS
Returns the default service provider for the system overridden by any parent class
that has Service { provider => $my_service_provider } specified to cause an override.
This is useful when we actually need to know the clients service provider and allow them
to also override it in case they decide they need a different one due to puppet not picking
the right one for their new or old Operating System.
Example:
Centos 7(systemd)
{
$var = service_provider_func()
}
>>> $var prints 'systemd'
{
Service {
provider => 'upstart'
}
$var = service_provider_func()
}
>>> $var prints 'upstart'
EOS
) do |args|
override = self.lookupdefaults('Service')[:provider].value
override = lookupvar('service_provider') if override.nil? || override.empty?
return override
end
end
@hunner
Copy link

hunner commented Oct 1, 2015

include postgresql::server
Service <| name == 'postgresql' |> {
  provider => 'systemd',
}

@daenney
Copy link

daenney commented Oct 1, 2015

File <| name == 'my init script' |> {
  content/source => something
}

If it's a file resource of the type file { /etc/init.d/bla: } then you don't really need an override at all, just drop your own with file { '/etc/systemd/...: }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment