On 4 September 2011 20:09, Nils Anspach <nils.ansp...@googlemail.com> wrote: > Hello list, > > I think there is something wrong with the OpenBSD package provider > in Puppet 2.6.3 (4.9) and 2.7.1 (snapshot of 17/08):
http://www.mail-archive.com/puppet-dev@googlegroups.com/msg14497.html > If a 'package' resource is given a 'source' attribute that does not > point to a particular package but to a repository instead and the > PKG_PATH parameter in Puppet's environment is unset, an error is > misleadingly raised. For instance, > > package { 'wget': > ensure => 'present', > source => 'ftp://<mirror>/pub/OpenBSD/4.9/packages/i386/:', > } > > with PKG_PATH unset fails with > > err: /Stage[main]//Node[haumea]/Package[wget]/ensure: change > from absent to present failed: Could not set 'present on > ensure: undefined local variable or method `version' for > #<Puppet::Type::Package::ProviderOpenbsd:0x214f7d760> at > /etc/puppet/manifests/site.pp:147 > > This is due to 'pkg_info' being called on 'wget' in the provider > without PKG_PATH being set to 'source'. Even if PKG_PATH was set > in the environment, the current implementation would be incorrect, > since it then checks for 'wget's version in PKG_PATH, but installs > it from 'source' afterwards. > > The patch below solves this issue, although someone with real Ruby > experience may likely provide a better fix: > > Nils > > --- lib/puppet/provider/package/openbsd.rb.orig Sun Sep 4 00:48:08 2011 > +++ lib/puppet/provider/package/openbsd.rb Sun Sep 4 02:00:37 2011 > @@ -62,7 +62,7 @@ > > if @resource[:source][-1,1] == ::File::PATH_SEPARATOR > e_vars = { :PKG_PATH => @resource[:source] } > - full_name = [ @resource[:name], get_version || @resource[:ensure], > @resource[:flavor] ].join('-').chomp('-') > + full_name = [ @resource[:name], get_version(e_vars) || > @resource[:ensure], @resource[:flavor] ].join('-').chomp('-') > else > e_vars = {} > full_name = @resource[:source] > @@ -71,26 +71,28 @@ > Puppet::Util::Execution::withenv(e_vars) { pkgadd full_name } > end > > - def get_version > - execpipe([command(:pkginfo), " -I ", @resource[:name]]) do |process| > - # our regex for matching pkg_info output > - regex = /^(.*)-(\d[^-]*)[-]?(\D*)(.*)$/ > - fields = [ :name, :version, :flavor ] > - master_version = 0 > - > - process.each do |line| > - if match = regex.match(line.split[0]) > - # now we return the first version, unless ensure is latest > - version = match.captures[1] > - return version unless @resource[:ensure] == "latest" > - > - master_version = version unless master_version > version > + def get_version(e_vars) > + Puppet::Util::Execution::withenv(e_vars) { > + execpipe([command(:pkginfo), " -I ", @resource[:name]]) do |process| > + # our regex for matching pkg_info output > + regex = /^(.*)-(\d[^-]*)[-]?(\D*)(.*)$/ > + fields = [ :name, :version, :flavor ] > + master_version = 0 > + > + process.each do |line| > + if match = regex.match(line.split[0]) > + # now we return the first version, unless ensure is latest > + version = match.captures[1] > + return version unless @resource[:ensure] == "latest" > + > + master_version = version unless master_version > version > + end > end > - end > - > - return master_version unless master_version == 0 > - raise Puppet::Error, "#{version} is not available for this package" > - end > + > + return master_version unless master_version == 0 > + raise Puppet::Error, "No version available for this package." > + end > + } > rescue Puppet::ExecutionFailure > return nil > end > >