I was vexed by this error when setting up a host with Puppet 3.6.2 on FreeBSD 9.2 recently:
Error: Could not set 'present' on ensure: uninitialized class variable @@lock in Object at 52:/usr/local/etc/puppet/modules/ldap/manifests/init.pp
Error: Could not set 'present' on ensure: uninitialized class variable @@lock in Object at 52:/usr/local/etc/puppet/modules/ldap/manifests/init.pp
Wrapped exception:
uninitialized class variable @@lock in Object
Error: /Stage[main]/Ldap/Package[net/nss_ldap]/ensure: change from absent to present failed: Could not set 'present' on ensure: uninitialized class variable @@lock in Object at 52:/usr/local/etc/puppet/modules/ldap/manifests/init.pp
The line it referred to was trying to install the net/nss_ldap
package. I had
run pkg2ng
on the host and included the pkgng
module in the node’s manifest.
When I searched for @@lock
in the Puppet source code, the only references I
found were from the freebsd
package provider. That provider uses the
deprecated pkg_
commands and for some reason is included in Puppet while
pkgng
is not.
[longb4-local@testdb /usr/ports/sysutils/puppet]$ sudo make fetch extract patch configure
[longb4-local@testdb /usr/ports/sysutils/puppet]$ cd work/puppet-3.6.2/
[longb4-local@testdb /usr/ports/sysutils/puppet/work/puppet-3.6.2]$ find . -exec grep -HnsiI '@@lock' {} \;
./lib/puppet/provider/package/freebsd.rb:18: class_variable_set(:@@lock, Mutex.new)
./lib/puppet/provider/package/freebsd.rb:73: @@lock.synchronize do
Solution
Since Puppet was trying to use the non-working pkg_
commands, I made it use
the pkgng
package provider when installing packages on the affected node by
adding this to the node manifest:
Package {
provider => pkgng,
}
After that, Puppet runs completed successfully.