I am new to chef and have little understanding of Ruby.
I am getting below error during chef-client run
FATAL: NoMethodError: ruby_block[modify_token] had an error: NoMethodError: undefined method `gsub' for #Chef::DelayedEvaluator:0x0000000003542100
In my recipe, I am repalcing '&' with "&"
Below is my recipe
azuresecret app_node['SAS_Token'] do
key_vault_name node['key_vault_names']['Test']
end
ruby_block 'modify_token' do
block do
sastoken = lazy { node.run_state['SAS_Token'] }
modified_token = sastoken.gsub(/[&]/, '&')
storage_conn_str = File.join(storage_conn_str , modified_token)
end
action :run
end
You can either do the gsub sastoken lazy block or you can make modified_token lazy as well. The way it's setup now the gsub is trying to run before the sastoken value is set since that's lazy.
I made the other variables lazy. I printed varaible values in log. I got below values.
SAS Token: #Chef::DelayedEvaluator:0x0000000006e28c80@c:/chef/cache/cookbooks/internal_apps/recipes/tableStorage_api.rb:20
SAS Token after replacement: #
Also, I added new attribute in ruby_block to use in webapp resource and made it lazy. But still I am not getting value for 'storage_conn_str'
azuresecret app_node['SAS_Token'] do
key_vault_name node['key_vault_names']['Test']
end
ruby_block 'modify_token' do
block do
sastoken = lazy { node.run_state['SAS_Token'] }
Chef::Log.info("SAS Token: #{sastoken}")
modified_token = lazy { sastoken.gsub(/[&]/, '&') }
Chef::Log.info("SAS Token after replacement: #{modified_token}")
storage_conn_str = lazy { File.join(storage_conn_str , modified_token)}
Chef::Log.info("storage connection string: #{storage_conn_str}")
node.default[cookbook_name][recipe_name]["storage_conn_str"] = lazy {storage_conn_str }
end
action :run
end