voxpupuli / puppet-pkgng

A Puppet package provider for FreeBSD's PkgNG package manager.
https://forge.puppet/com/puppet/pkgng
Apache License 2.0
39 stars 33 forks source link

Not overriding default provider w/ PE 3.3.0 #50

Closed mpounsett closed 8 years ago

mpounsett commented 10 years ago

It looks like the default provider isn't being overridden when pkgng is used on PE 3.3.0 (puppet 3.6.2, Ubuntu 12.04 LTS) with an OSS puppet 3.4.2 client (FreeBSD). The pkgng provider is being executed, but so is the default provider, and that's causing errors to be thrown. For example, using the pkgng provider to make sure that 'pkg' is at the latest version throws this error:

root@testbox:~ # puppet agent -t
Info: Retrieving plugin
Info: Loading facts in /var/puppet/lib/facter/concat_basedir.rb
Info: Loading facts in /var/puppet/lib/facter/staging_http_get.rb
Info: Loading facts in /var/puppet/lib/facter/root_home.rb
Info: Loading facts in /var/puppet/lib/facter/pe_postgres_default_version.rb
Info: Loading facts in /var/puppet/lib/facter/pkgng.rb
Info: Loading facts in /var/puppet/lib/facter/facter_dot_d.rb
Info: Loading facts in /var/puppet/lib/facter/puppet_vardir.rb
Info: Loading facts in /var/puppet/lib/facter/iptables_version.rb
Info: Loading facts in /var/puppet/lib/facter/iptables_persistent_version.rb
Info: Loading facts in /var/puppet/lib/facter/ip6tables_version.rb
Info: Loading facts in /var/puppet/lib/facter/pe_version.rb
Info: Loading facts in /var/puppet/lib/facter/postgres_default_version.rb
Info: Loading facts in /var/puppet/lib/facter/windows.rb
Info: Loading facts in /var/puppet/lib/facter/pe_build.rb
Info: Loading facts in /var/puppet/lib/facter/pe_puppetdb_server_status.rb
Info: Loading facts in /var/puppet/lib/facter/custom_auth_conf.rb
Info: Loading facts in /var/puppet/lib/facter/platform_tag.rb
/usr/local/lib/ruby/site_ruby/1.9/puppet/provider/package/freebsd.rb:18: warning: class variable access from toplevel
/usr/local/lib/ruby/site_ruby/1.9/puppet/provider/package/freebsd.rb:19: warning: class variable access from toplevel
Info: Caching catalog for testbox.conundrum.com
Error: Failed to apply catalog: Parameter ensure failed on Package[pkg]: Provider must have features 'upgradeable' to set 'ensure' to 'latest' at /etc/puppetlabs/puppet/environment/production/modules/packaging/manifests/freebsd/package.pp:10
Wrapped exception:
Provider must have features 'upgradeable' to set 'ensure' to 'latest'

If I instead try to set it to simply 'installed' the old provider throws this error instead:

/usr/local/lib/ruby/site_ruby/1.9/puppet/provider/package/freebsd.rb:18: warning: class variable access from toplevel
/usr/local/lib/ruby/site_ruby/1.9/puppet/provider/package/freebsd.rb:19: warning: class variable access from toplevel
Info: Caching catalog for testbox.conundrum.com
Info: Applying configuration version '1406498853'
Error: pkg: not in required origin format: .*/<port_category>/<port_name>
Error: /Stage[main]/Packaging::Freebsd::Package/Package[pkg]/ensure: change from absent to present failed: pkg: not in required origin format: .*/<port_category>/<port_name>

The pkgng provider module is in the basemodulepath ahead of the stock PE modules.

zachfi commented 10 years ago

I use the following in site.pp

case $::osfamily {
...
  'FreeBSD': {
    if $pkgng_enabled {
      Package { provider => pkgng }
      Cron { environment => 'PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin' }
    }
  }
...
}

I've not tested this module with PE, so I don't really know what to expect.

mpounsett commented 10 years ago

PE itself shouldn't make a difference in this case .. it's basically just a 3.6.2 server on Ubuntu with a 3.4.2 client on FreeBSD.

I run a similar setup.. I've just put it into a module so that I can expand it to cover configuration of whatever the local packaging system is .. currently it just manages FreeBSD, however.

class packaging {
    include packaging::vars
    if $::osfamily == 'FreeBSD' {
        include packaging::freebsd::files
        include packaging::freebsd::package
    }
}
...
class packaging::vars {
    if $::osfamily == 'FreeBSD' {
        $pkgname    = 'pkg'
        $repo       = hiera('pkgng-repo')
        pkgng::repo { 'tinderbox':
            packagehost => 'redacted',
            repopath => "/packages/$repo/All",
        }
        Package { provider => pkgng }
    }
}
...
class packaging::freebsd::files {
    file { '/etc/pkg/FreeBSD.conf':
        ensure  => absent,
        notify  => Exec['pkg update'],
    }
}
...
class packaging::freebsd::package {
        package { $packaging::vars::pkgname:
                ensure  => installed,
        }
}
zachfi commented 10 years ago

The difference is that placing the code in site.pp avoids all scoping, where in your example containment will come into play. Could you try placing the Package {} default in site.pp and see if that helps your issue? Without submitting the provider as a PR to puppet itself and overriding the default in core puppet, I'm not sure how I can help in this regard. Unless I'm overlooking something.

mpounsett commented 10 years ago

Ahh okay. I didn't realize there was a potential scoping issue. I've moved the Package {} default into site.pp as you suggested and it now looks like this is working as expected. Thanks for the info! If I might suggest, it would probably be helpful to include a note about this in the setup instructions for the module.

zachfi commented 10 years ago

If you wouldn't mind, just flesh out the Usage section a bit and submit a PR. You're right, the docs could you improvement in this area.

zachfi commented 8 years ago

This has been resolved. Puppet4 now has the provider and is default for the package provider on FreeBSD.