Reputation: 40398
Can anyone help me with this please?
NoMethodError
-------------
undefined method `execute' for Chat::Mattermost:Class
Relevant File Content: (file name libraries/chat.rb
)
4:
5: module Chat
6: class Mattermost
7:
8: def self.log_to_chat(message)
9>> execute "echo" do
10: command "echo #{message}"
11: end
12: end
13:
14: end
15: end
16:
I read that DSL syntax isn't available in a definition, so I am guessing I need to do something resembling r = Chef::Resource::Execute.new("echo #{message}")
and r.run_command :run
but I'm not quite so sure how to do it.
Other relevant code, my method is "called" like this:
log "this is a message" do
level :info
notifies :run, Chat::Mattermost.log_to_chat("#{name}"), :immediately
end
edit: second attempt
NoMethodError
-------------
undefined method `events' for nil:NilClass
for code:
5: require 'chef/resource/execute'
6:
7: module Chat
8: class Mattermost
9:
10: def self.log_to_chat(message)
11: cmd = Chef::Resource::Execute.new("echo #{message}")
12>> cmd.run_action(:run)
13:
Upvotes: 0
Views: 130
Reputation: 1525
notifies :run, Chat::Mattermost.log_to_chat("#{name}"), :immediately
notifies
you should pass string which will be used to search resource in chef context.If you want to enhance log resource provider, you should implement your own, similar to this, put it in libraries
and call log
resource with your newly implemented class name as provider.
log 'this is a message' do
provider Chef::Provider::Log::MyCustomLog
end
Upvotes: 1