[chef] Unable to use chef_gem in custom provider during first run


Chronological Thread 
  • From: < >
  • To:
  • Subject: [chef] Unable to use chef_gem in custom provider during first run
  • Date: Sat, 30 Nov 2013 19:24:29 -0800 (PST)

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:in
`new'
/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:in
`require'
/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:in
`require'
/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:in
`require'
/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:in
`schema_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:in
`instance_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:in
`run_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:in
`run_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:in
`each'
/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:in
`block 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:in
`call_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:in
`iterate'
/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:in
`execute_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:in
`converge'
/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:in
`run'
/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:in
`block 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:in
`run_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 `<main>'


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


  • [chef] Unable to use chef_gem in custom provider during first run, gallagher.peter, 11/30/2013

Archive powered by MHonArc 2.6.16.

§