0
votes

Hi Guys I am working on below code snippet. I tried various combinations with I am not able to call manage_auth or authorized_users_ldap from RemoteFile

I am able to notify manage_auth or authorized_users_ldap from ruby_block "manage_operator" but not from RemoteFile

I want to trigger either of the 2 (manage_auth or authorized_users_ldap) if manage_operator_flag is equal to 1. Thus I tried putting a notify on remote_file, but that is not getting triggered. Please let me know what I am doing wrong

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
1

1 Answers

0
votes

looking at the manage_operator ruby block, you should drop the then keyword since there is no such keyword in ruby.

change:

if (manage_operator_flag) then

to:

if (manage_operator_flag)

and just like you did in manage_auth ruby block, add log output within the condition block.

also, you should definitly execute chef-client with higher verbosity and examine the log. you can do that by appending --log_level debug to chef-client, that is:

$ chef-client --log_level debug

i would also recommend you to use remote_file resource directly, rather then using ruby_block to invoke remote_file dynamically (at run\convergance-time)