簡體   English   中英

Chef:遠程文件無法通知 Execute 或 Ruby_Block

[英]Chef: Remote File not able to notify Execute or Ruby_Block

嗨伙計們,我正在處理下面的代碼片段。 我嘗試了各種組合,但無法從 RemoteFile 調用manage_authauthorized_users_ldap

我可以從 ruby_block "manage_operator" 但不能從 RemoteFile 通知manage_authauthorized_users_ldap

如果 manage_operator_flag 等於 1,我想觸發 2 個( manage_authauthorized_users_ldap )中的任何一個。因此我嘗試在 remote_file 上放置一個通知,但這沒有被觸發。 請讓我知道我做錯了什么

ruby_block "manage_auth" do
  block do
    Chef::Log.info("MANAGE AUTH")
  end
  action :nothing
end

ruby_block "manage_operator" do
  block do
    manage_operator_flag = (cfg.fetch("manage.operators", 0) == 1)
    if (manage_operator_flag) then
      f =  Chef::Resource::File::RemoteFile.new("#{node['ucms']['dir']}/bin/ucms_authorized_users_ldap.json", run_context)
      f.source "https://ca.#{c}.#{p}.axiadids.net:4443/ucms_authorized_users_ldap.json"
      f.retries 3
      f.retry_delay 10
      f.ignore_failure true
      # f.run_action :create
      f.action :create
      # f.notifies :run, "execute[authorized_users_ldap]"
      # f.notifies(:run, Chef::Resource::Execute.new("authorized_users_ldap", run_context))
      f.notifies :run, "ruby_block[manage_auth]"
    end
  end
end

execute "authorized_users_ldap" do
  command "touch /tmp/test"
  action :nothing
end

查看manage_operator ruby 塊,您應該刪除then關鍵字,因為 ruby 中沒有這樣的關鍵字。

改變:

if (manage_operator_flag) then

至:

if (manage_operator_flag)

就像您在manage_auth ruby 塊中所做的那樣,在條件塊中添加日志 output 。

此外,您應該明確地執行更詳細的 chef-client 並檢查日志。 您可以通過將--log_level debug附加到 chef-client來做到這一點,即:

$ chef-client --log_level debug

我還建議您直接使用remote_file資源,而不是使用ruby_block動態調用remote_file (在運行\收斂時間)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM