Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-1073

Support common package name in two different providers

    XMLWordPrintable

Details

    • 3
    • Platform Client 2014-11-26, Platform Client 2014-12-17, Platform Client 2015-01-07, Platform Client 2015-01-21

    Description

      I have a common package name, that's in two different package managers
      (one with yum the other with gem)

              package { "remove-mysql":
                      name     => "mysql",
                      provider => "yum",
                      ensure   => absent,
              }
      

      ---------------------------------------------------------

              package { "gem-mysql":
                      name    => "mysql",
                      ensure   => "2.7",
                      provider => gem,
              }
      

      ---------------------------------------------------------

      I get this error.

      Jul  3 08:43:34 puppetd[11872]: Could not retrieve catalog:
      Puppet::Parser::AST::Resource failed with error ArgumentError: Cannot
      alias Package[gem-mysql] to mysql; resource Package[mysql] already
      exists at /etc/puppet/modules/ruby-mysql/manifests/init.pp:11 on node 
      


      The solution to this was to generate a uniqueness key based on [name, provider], as mentioned by andy. That allows the example above to work, but doesn't resolve when multiple providers manage the same package. Several changes were needed:

      1. Set paramclass(:provider).isnamevar on the Package type, so the :provider parameter is recognized as part of the namevar.
      2. Overloaded the title_patterns method on the Package type, so the title could be parsed into namevars (it only sets :name, not :provider).
      3. The catalog assumed that isomorphic resources only needed to be aliased if the title and name didn't match. An alias is automatically created for a resource's title; if titles don't match but the namevar does they should still refer to the same thing. However, name is not equivalent to namevar for a composite namevar, so the test for whether to create an alias uses the uniqueness_key (an array containing all namevars). The impact of this change is to correctly identify when a resource with a composite namevar has already been created, as in

        package { "add-mysql":
          name   => "mysql",
          ensure => present,
        }
         
        package { "mysql":
          ensure => present,
        }
        

      4. The change to catalog means that creating aliases now depends on the uniqueness_key. That implementation in resource type could end up returning an array without the name specified if the :name parameter wasn't specifically specified. This change was made so conflicts between implicit and explicit default provider are detected at catalog compilation instead of trying to apply the manifest.

      Changes (1) and (2) are required for any provider that uses a composite namevar.

      Impact of this change:

      • Querying resources by name on the command-line when multiple packages from different providers are specified only returns the package with the default provider (PUP-3721).
      • Referring to Package resources by Package[$namevar] in Puppet code doesn't work for a composite namevar, so it no longer works for Package. Querying by Package[$title] still works. This is a breaking change in Puppet 4.

      Attachments

        Issue Links

          Activity

            People

              michael.smith Michael Smith
              redmine.exporter redmine.exporter
              Kurt Wall Kurt Wall
              Votes:
              16 Vote for this issue
              Watchers:
              28 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support