2016-10-14 4 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이 아닌 일반 오래된 루비 코드 만 실행합니다. 중요한 로직을 라이브러리 메소드에 넣고 리소스와 이벤트 핸들러에서 호출 할 수 있습니다.

+0

그런 다음 라이브러리 메소드가 DSL을 사용할 수 있습니까? 'chat_message'는 차례대로'execute do \ n command "curl ...."을 사용하기 때문에 \ n end' – vikingsteve

+0

아니요, 당신은 DSL에서 일반 Ruby를 호출 할 수 있지만 그 반대는 아닙니다. – coderanger

+0

chef :: http 클라이언트 API를 사용해야합니다. – coderanger