Unable to use chef_gem in custom provider during first run


#1

I have a recipe that downloads a compiled version of the ruby-oci8 gem and
installs it. Then I use a custom LWRP to access the database and populate a
schema e.g.:

recipe/default.rb

oci8 = remote_file node[‘oracle’][‘gems’][‘oci8’][‘archive’] do
source node[‘oracle’][‘gems’][‘oci8’][‘url’]
checksum node[‘oracle’][‘gems’][‘oci8’][‘checksum’]
mode "0644"
action :nothing
end
oci8.run_action(:create)

chef_gem “ruby-oci8” do
action :install
source node[‘oracle’][‘gems’][‘oci8’][‘archive’]
end

providers/schema_oracle.rb

private
def database_connection
@db ||= begin
require 'oci8’
connection = OCI8.new("#{node[“database”][“username”]}",
"#{node[“database”][“password”]}",
"#{node[‘oracle’][‘db’][‘service_name’]}")
Chef::Log.debug(“Created connection to #{connection.username}”)
connection
end
end

But, during the first run of chef-solo when I try to require 'oci8' in my
provider I get an Argument error (shown below). Running chef-solo a second time
does not produce this error and the cookbook completes as expected.

===
ArgumentError

wrong number of arguments (2 for 0…1)

Cookbook Trace:

/tmp/vagrant-chef-1/chef-solo-1/cookbooks/database/providers/schema_oracle.rb:10:in
`database_connection’

The full stack trace from chef is:

Generated at 2013-12-01 02:47:58 +0000
ArgumentError: my_schema[example] (my_app::default line 73) had an error:
ArgumentError: wrong number of arguments (2 for 0…1)
/opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
initialize' /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:innew’
/opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
require' /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:inrequire’
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.1.5-x86_64-linux/lib/oci8.rb:81:in
<top (required)>' /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:inrequire’
/opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in
rescue in require' /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:inrequire’
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/my_app/providers/schema_oracle.rb:10:in
database_connection' /tmp/vagrant-chef-1/chef-solo-1/cookbooks/my_app/providers/schema_oracle.rb:27:inschema_empty?’
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/my_app/providers/schema_oracle.rb:53:in
block in class_from_file' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/provider/lwrp_base.rb:138:ininstance_eval’
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/provider/lwrp_base.rb:138:in
block in action' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/provider.rb:114:inrun_action’
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/resource.rb:606:in
run_action' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/runner.rb:50:inrun_action’
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/runner.rb:82:in
block (2 levels) in converge' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/runner.rb:82:ineach’
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/runner.rb:82:in
block in converge' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/resource_collection.rb:94:inblock in execute_each_resource’
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/resource_collection/stepable_iterator.rb:116:in
call' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/resource_collection/stepable_iterator.rb:116:incall_iterator_block’
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/resource_collection/stepable_iterator.rb:85:in
step' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/resource_collection/stepable_iterator.rb:104:initerate’
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/resource_collection/stepable_iterator.rb:55:in
each_with_index' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/resource_collection.rb:92:inexecute_each_resource’
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/runner.rb:81:in
converge' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/client.rb:404:inconverge’
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/client.rb:469:in
do_run' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/client.rb:200:inrun’
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/application.rb:190:in
run_chef_client' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/application/solo.rb:239:inblock in run_application’
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/application/solo.rb:231:in
loop' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/application/solo.rb:231:inrun_application’
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/lib/chef/application.rb:73:in
run' /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.4/bin/chef-solo:25:in<top (required)>’
/usr/bin/chef-solo:23:in load' /usr/bin/chef-solo:23:in

From the stacktrace above
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.1.5-x86_64-linux/lib/oci8.rb:81
is trying to require
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ruby-oci8-2.1.5-x86_64-linux/lib/oci8lib_191.so
which seems to be the root cause of the problem, but I don’t know enough about
Chef to debug this any further than that. This is my first attempt at a Chef
cookbook so I may be overlooking something obvious but I would really
appreciate any pointers.

Thanks,

Peter