Undefined method `getSearchInstanceDirectory' for #<#<Class:0x00000000046d8f90>:0x0000000005b803d0>

Hello,
We are moving a provider from the provider directory to the resource directory to update old recipes in our deployment cookbook. This was created back when we were using Chef 10. Currently on Chef 12.

In this resource file in an action which is being specifically called from the deployment recipe we have this custom method defined. This works under the provider directory on nodes using chef 12.5.1 and ruby 1.8.7. When running on a node using chef 15.9.17 and ruby 2.5.1 we get the undefined method error.

Here are the bits from the action in the resource file:

def getSearchInstanceDirectory(node, phase)
  instance_id=node['macaddress'].downcase
  instance_id.gsub!(/:/, "")
  instance_id=instance_id[-6..-1]
  instance_name = "/var/#{phase}-content-#{instance_id}"
  instance_name
end

search_query = "(chef_environment:content_#{phase}_web_env AND role:content_web_server)"
servers = []
server_nodes = search(:node, search_query)
  
server_nodes.each do |server_node|
  apache_root_dir = getSearchInstanceDirectory(server_node, phase)
  server_entry = "\"#{server_node.name}\":\"#{apache_root_dir}/www/html/sitemap\""
  puts server_entry
  servers << server_entry
end

Here is more of the error:

NoMethodError
-------------
undefined method `getSearchInstanceDirectory' for #<#<Class:0x00000000046d8f90>:0x0000000005b803d0>

Cookbook Trace:
---------------
/var/cache/chef/cookbooks/deployment/resources/batch_intl.rb:62:in `block (2 levels) in class_from_file'
/var/cache/chef/cookbooks/deployment/resources/batch_intl.rb:61:in `each'
/var/cache/chef/cookbooks/deployment/resources/batch_intl.rb:61:in `block in class_from_file'
/var/cache/chef/cookbooks/deployment/libraries/TimingWrapperModule.rb:18:in `run_action'

Resource Declaration:
---------------------
# In /var/cache/chef/cookbooks/deployment/recipes/war.rb

 96: deployment_configure "pre install configuration" do
 97:   action :pre_install
 98:   configs configMap
 99:   provider provider
100:   timer_config :callback_config => $callback_config, :key => "pre_install_configuration_run"
101: end
102:

I have tried moving the custom method to a library helpers.rb file resulting in the same error. Perhaps I'm missing something here?

helpers.rb:

module Deployment
  module Helpers
    def self.getSearchInstanceDirectory(node, phase)
      instance_id=node['macaddress'].downcase
      instance_id.gsub!(/:/, "")
      instance_id=instance_id[-6..-1]
      instance_name = "/var/#{phase}-content-#{instance_id}"
      instance_name
    end
  end
end

Then added this to the resource file which I believe isn't getting loaded because the action above is getting called from the recipe specifically.

action_class do
  include ::Deployment::Helpers
end

I have verified that the above code works on the newer node using chef-shell.

Thanks

-George

I decided to hack the resource and put all of the custom method steps in to the server_nodes.each block to make it work. Would be nice to find out why the custom method doesn't work on new nodes though.