嗨,伙计们,我正在处理下面的代码片段。我尝试了各种组合,无法从远程文件调用manage_auth或authorized_users_ldap
我能够从"manage_operator"ruby_block通知manage_auth或authorized_users_ldap,但不能从远程文件通知
如果 2 等于 1,我想触发 2(manage_auth或authorized_users_ldap(中的任何一个manage_operator_flag。因此,我尝试在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)
就像您在 Ruby 块中所做的manage_auth
一样,在条件块中添加日志输出。
此外,您应该明确执行具有更高详细程度的 Chef-客户端并检查日志。 您可以通过将--log_level debug
附加到 Chef-Client 来执行此操作,即:
$ chef-client --log_level debug
我还建议您直接使用remote_file
资源,而不是使用ruby_block
动态调用remote_file
(在运行\收敛时(