The poise cookbook provides patterns and helpers for writing reusable Chef code.
Create a libraries/default.rb
file in your cookbook like so:
class Chef
class Resource::MyResource < Resource
include Poise
actions(:enable, :disable)
attribute(:path, kind_of: String)
end
class Provider::MyResource < Provider
def action_enable
converge_by("enable resource #{new_resource.name}") do
notifying_block do
... # Normal Chef recipe code goes here
end
end
end
end
end
You can then use this resource like any other Chef resource:
my_resource 'one' do
path '/tmp'
end
Module: Poise::Provider::NotifyingBlock