Is "notifies" clause supported in LWRP?


#1

I observed that in case of LWRP, “notifies” clause don’t work as expected (i.e.
it doesn’t notify other resource with given action). Please let me know if
there are any mistakes in the code.

I declared LWRP as -

resources/execute.rb

actions :execute

attribute :name, :kind_of => String, :name_attribute => true
attribute :command, :kind_of => String

providers/remote.rb

action :execute do
execute “remote_exe_#{new_resource.command}” do
command "#{new_resource.command}"
end
end

recipes/default.rb

Remote_execute “lwrp_uninst” do <<<< cookbook name => Remote
command "sudo rpm -e libyaml-0.1.4-1ll.el6.rf.x86_64"
action :nothing
provider “Remote_remote” <<<< cookbook name =>
Remote
end

Remote_execute “lwrp_inst” do <<<< cookbook name =>
Remote
command "sudo rpm -ivh
/home/aditya/Downloads/libyaml-0.1.4-1.el6.rf.x86_64.rpm"
action :execute
provider “Remote_remote” <<<< cookbook name =>
Remote
notifies :execute, “Remote_execute[lwrp_uninst]”, :immediately
end

===============================================================

If I try same thing with existing resource e.g. “execute”, it works as
expected.

execute “uninstall” do
command "sudo rpm -e libyaml-0.1.4-1.el6.rf.x86_64"
action :nothing
end

execute “install” do
command "sudo rpm -ivh
/home/aditya/Downloads/libyaml-0.1.4-1.el6.rf.x86_64.rpm"
notifies :run, “execute[uninstall]”, :immediately
end

Thanks,
Aditya Nitsure


#2

Hi.

Just stick “use_inline_resources” at the top of your provider definition.

-s

On Wed, Mar 20, 2013 at 8:31 AM, adityanitsure@yahoo.co.uk wrote:

I observed that in case of LWRP, “notifies” clause don’t work as expected (i.e.
it doesn’t notify other resource with given action). Please let me know if
there are any mistakes in the code.

I declared LWRP as -

resources/execute.rb

actions :execute

attribute :name, :kind_of => String, :name_attribute => true
attribute :command, :kind_of => String

providers/remote.rb

action :execute do
execute “remote_exe_#{new_resource.command}” do
command "#{new_resource.command}"
end
end

recipes/default.rb

Remote_execute “lwrp_uninst” do <<<< cookbook name => Remote
command "sudo rpm -e libyaml-0.1.4-1ll.el6.rf.x86_64"
action :nothing
provider “Remote_remote” <<<< cookbook name =>
Remote
end

Remote_execute “lwrp_inst” do <<<< cookbook name =>
Remote
command "sudo rpm -ivh
/home/aditya/Downloads/libyaml-0.1.4-1.el6.rf.x86_64.rpm"
action :execute
provider “Remote_remote” <<<< cookbook name =>
Remote
notifies :execute, “Remote_execute[lwrp_uninst]”, :immediately
end

===============================================================

If I try same thing with existing resource e.g. “execute”, it works as
expected.

execute “uninstall” do
command "sudo rpm -e libyaml-0.1.4-1.el6.rf.x86_64"
action :nothing
end

execute “install” do
command "sudo rpm -ivh
/home/aditya/Downloads/libyaml-0.1.4-1.el6.rf.x86_64.rpm"
notifies :run, “execute[uninstall]”, :immediately
end

Thanks,
Aditya Nitsure


#3

A longer explanation here:

http://docs.opscode.com/breaking_changes_chef_11.html#inline-compile-mode-for-lightweight-resources


Daniel DeLeo

On Wednesday, March 20, 2013 at 6:13 AM, Sean OMeara wrote:

Hi.

Just stick “use_inline_resources” at the top of your provider definition.

-s

On Wed, Mar 20, 2013 at 8:31 AM, <adityanitsure@yahoo.co.uk (mailto:adityanitsure@yahoo.co.uk)> wrote:

I observed that in case of LWRP, “notifies” clause don’t work as expected (i.e.
it doesn’t notify other resource with given action). Please let me know if
there are any mistakes in the code.

I declared LWRP as -

resources/execute.rb

actions :execute

attribute :name, :kind_of => String, :name_attribute => true
attribute :command, :kind_of => String

providers/remote.rb

action :execute do
execute “remote_exe_#{new_resource.command}” do
command "#{new_resource.command}"
end
end

recipes/default.rb

Remote_execute “lwrp_uninst” do <<<< cookbook name => Remote
command "sudo rpm -e libyaml-0.1.4-1ll.el6.rf.x86_64"
action :nothing
provider “Remote_remote” <<<< cookbook name =>
Remote
end

Remote_execute “lwrp_inst” do <<<< cookbook name =>
Remote
command "sudo rpm -ivh
/home/aditya/Downloads/libyaml-0.1.4-1.el6.rf.x86_64.rpm"
action :execute
provider “Remote_remote” <<<< cookbook name =>
Remote
notifies :execute, “Remote_execute[lwrp_uninst]”, :immediately
end

===============================================================

If I try same thing with existing resource e.g. “execute”, it works as
expected.

execute “uninstall” do
command "sudo rpm -e libyaml-0.1.4-1.el6.rf.x86_64"
action :nothing
end

execute “install” do
command "sudo rpm -ivh
/home/aditya/Downloads/libyaml-0.1.4-1.el6.rf.x86_64.rpm"
notifies :run, “execute[uninstall]”, :immediately
end

Thanks,
Aditya Nitsure