Question concerning actions in resources and providers


#1

Greetings,

I’m a bit lost how this works:

resources/ring.rb

actions :set
default_action :set


property :interface, String, name_property: true
property :rx, Integer
property :tx, Integer

load_current_value do
  rx 512
  tx 512
end

providers/ring.rb

use_inline_resources


action :set do

  converge_if_changed :rx do
    log 'aaa' do
      message 'aaaa'
      level :info
    end
  end

  converge_if_changed :tx do
    log 'bbbb' do
      message 'bbbb'
      level :info
    end
  end

end

recipes/default.rb

mycookbook_ring 'eth0' do
  rx 512
  tx 512
end

For some reason chef ignores load_current_value block and as a result converge_if_changed is always true.

Tho it works as designed if I append all stuff from providers/ring.rb to resources/ring.rb .

I have :

# chef-client -v
Chef: 12.21.3

Is this a bug or feature? Seems like it’s pointless to use providers/* then


#2

One more question, is “/providers” directory deprecated? I also can’t really find any examples how to work with providers, tho I can see a lot of examples for /resources .


#3

The older style isn’t deprecated per se, there just isn’t much reason to use it these days. Since 12.5, the preferred style is to include both the resource description and action code in one file (under resources/). You can’t mix-and-match on style, and load_current_value and converge_if_changed are part of the newer style “custom resource” (vs. “LWRP” for the older style, though both end up creating resource classes so the naming is a bit wibbly).


#4

I see, thanks a lot. I did some research and haven’t found that “providers” are considered as old style, good to know.