2016-10-14 9 views
0

私たちのノードではシェフクライアントがスケジュールされていますので、チャットでエラーが報告されるように例外処理を設定したいと思います。 シェフ例外処理 - > chat_message(LWRP)を使用する最も簡単な方法:run_failed

は、以前私が、私はLWRP chat_messageで例外を報告する シンプルな方法をしたいと思い、私のレシピ deploy_stuffで、今

chat_message do 
    message "Hello, World" 
    channel "deployments" 
end 

をチャットに投稿LWRPを書くためにここに役立つなった、と私はみましたこの:

# set up error handler 
Chef.event_handler do 
    on :run_failed do |exception| 
    chat_message ":exclamation: chef run_failed on #{Chef.run_context.node.name}: #{exception.message}" 
    end 
end 

は、それが動作しませんでしたしかし:

Running handlers: 
[2016-10-14T10:13:48+02:00] ERROR: Running exception handlers 
Running handlers complete 
[2016-10-14T10:13:48+02:00] ERROR: Exception handlers complete 
Chef Client failed. 10 resources updated in 20 seconds 
[2016-10-14T10:13:48+02:00] ERROR: undefined method `chat_message' for #<#<Class:0x00000005e1ef60>:0x00000005e1ee70> 
[2016-10-14T10:13:48+02:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) 

undefined method chat_messageの意味 - 私はここでLWRPを使用できませんか?

chat_messageを呼び出すレシピの他のコードが正常に機能するので、chat料理の本が含まれていることを確信しています。

答えて

1

いいえ、イベントハンドラはレシピDSLではなく、単純な古いRubyコードを実行します。重要なロジックをライブラリメソッドに置き、リソースとイベントハンドラの両方から呼び出すことができます。

+0

ライブラリメソッドはDSLを使用できますか? 'chat_message'は' execute do \ n command "curl ....を使います。\ n end' – vikingsteve

+0

いいえ、あなたはDSLからプレーンなRubyを呼び出すことができますが、その逆はできません。 – coderanger

+0

chef :: httpクライアントAPIを使用する必要があります。 – coderanger

関連する問題