Last active
August 29, 2015 14:07
-
-
Save Sharpie/3b2b12d9b3ef2cea6837 to your computer and use it in GitHub Desktop.
Spike of a composite key for the Puppet Package type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb | |
index 9a009db..4272bff 100644 | |
--- a/lib/puppet/type/package.rb | |
+++ b/lib/puppet/type/package.rb | |
@@ -239,6 +239,37 @@ module Puppet | |
end | |
end | |
+ # We call providify here so that we can set provider as a namevar. | |
+ # Normally this method is called after newtype finishes constructing this | |
+ # Type class. | |
+ providify | |
+ paramclass(:provider).isnamevar | |
+ | |
+ # We have more than one namevar, so we need title_patterns. However, we | |
+ # cheat and set the patterns to map to name only and completely ignore | |
+ # provider. So far, the logic that determines uniqueness appears to just | |
+ # "Do The Right Thing™" when the provider is explicitly set by the user. | |
+ # | |
+ # The following resources will be seen as uniqe by puppet: | |
+ # | |
+ # # Uniqueness Key: ['mysql', nil] | |
+ # package{'mysql': } | |
+ # | |
+ # # Uniqueness Key: ['mysql', 'gem'] | |
+ # package{'gem-mysql': | |
+ # name => 'mysql, | |
+ # provider => gem | |
+ # } | |
+ # | |
+ # This does not handle the case where providers like 'yum' and 'rpm' should | |
+ # clash. Also, declarations that implicitly use the default provider will | |
+ # clash with those that explicitly use the default. | |
+ def self.title_patterns | |
+ # This is the default title pattern for all types, except hard-wired to | |
+ # set only name. | |
+ [ [ /(.*)/m, [ [:name] ] ] ] | |
+ end | |
+ | |
newproperty(:package_settings, :required_features=>:package_settings) do | |
desc "Settings that can change the contents or configuration of a package. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After applying the above patch, the following manifest will apply on CentOS without duplicate resource errors: