Inline resource not to notify LWRP changed


#1

Hello,

I want to write a LWRP but some of the inline resources should allways run but not send notifications to other resources.

Here is a very basic example:

resource:
resource_name :test
property :content, String, default: “This is a Test”

action :run do
#This has to be run every time
ruby_block “Always run but do not set updated_by_last_action” do
block do
true
end
action :run
end

file "/tmp/test" do
	action :create
	content new_resource.content
	user "root"
	group "root"
end

end

Recipe:

test “My_Test” do
content node.environment
notifies :restart, ‘service[testservice]’, :delayed
end

#This should only be run if new_resource.content changed
service “testservice” do
action :nothing
end

I can’t figure out how to do it. Can somebody help me.

Kind Regards


#2

It works now.

I needed it to checkout a branch at a git repo temporary and then revert back to old branch at the end of my lwrp.

Here is what I did:
I execute the checkout in a not_if block at a dummy resource.

        ruby_block "Always run but do not set updated_by_last_action" do
            block do true end
            action :run
            not_if do 
                Chef::Log.info("#{new_resource.name} - Checkout #{branch}")
                git_cmd("checkout", "#{branch}", cwd: cwd) unless git_cmd("branch", cwd: cwd).stdout.include?("* #{branch}")
            end
        end

because the not_if executes successful, the ruby_block is never marked as updated.
With this I was able to execute the statement during converge phase.