Hello,
TL;DR; Easiest to change your attribute name
I couldn’t get your example to work but I can read and understand the code.
I’m guessing you are installing alert_logic on a Windows box? I’m assuming this because the default recipe of alert_logic looks like this
if platform_family?('windows')
include_recipe 'al_agents::_windows'
else
include_recipe 'al_agents::_linux'
end
The _linux recipe is
::Chef::Recipe.send(:include, AlAgents::Helpers)
include_recipe 'al_agents::selinux' if selinux_enabled?
include_recipe 'al_agents::rsyslog' if rsyslog_detected?
...
The windows is
::Chef::Recipe.send(:include, AlAgents::Helpers)
::Chef::Resource.send(:include, AlAgents::Helpers)
cache_dir = Chef::Config[:file_cache_path]
cached_package = ::File.join(cache_dir, agent_basename)
...
Focus on the
::Chef::Recipe.send(:include, AlAgents::Helpers)
::Chef::Resource.send(:include, AlAgents::Helpers)
This code is basically saying “extend the Chef::Recipe and Chef::Resource class and add the following methods to it”. Any instance of type Chef::Resource will have the methods in AlAgents::Helpers available to call!
AlAgents::Helpers does indeed have a service_name method https://github.com/alertlogic/al_agents/blob/f2ee5eec98d10413258a60939aba90b6bc4a6eaa/libraries/helpers.rb
Simplifying this do the following in a recipe
puts self.methods.grep(/service/) #=> no service name on windows Chef Client 12.8.1 service, macosx_service, windows_service
::Chef::Recipe.send(:include, AlAgents::Helpers)
::Chef::Resource.send(:include, AlAgents::Helpers)
puts self.methods.grep(/service/) # => includes service_name
In case you hadn’t noticed any code you write in your Chef libraries that aren’t namespaced are automatically included in Chef::Recipe and Chef::Resource which make is really simple for you to call your methods.
I’m conflicted about this type of coding practice, while it makes using methods simpler it means you can lose your code or it can be overwritten by code loaded later in the compile cycle. This is because all Classes in Ruby are open classes (thank goodness as we’ve monkey patched a lot of the Chef base classes to find issues), methods are defined as they are reached by the interpreter and most developers add their methods on a blanket basis i.e.
::Chef::Recipe.send(:include, AlAgents::Helpers)
::Chef::Resource.send(:include, AlAgents::Helpers)
Rather than
::Chef::Resource::Batch.send(:include, AlAgents::Helpers) # => Just extend batch resources
Extend just this class do not change the definition of Chef::Recipe
self.extend(AlAgents::Helpers)