ruby - Chef - Read a file from git repo at runtime and use parse value in recipe -
i read file checkout git repository parse config file , utilize info perform few resources commands.
git "/var/repository" action :sync end config = json.parse(file.read("/var/repository/config.json" )) config.each |job, flags| #do resources stuff here end
this not work because file doesn't exist @ compile time:
================================================================================ recipe compile error in /var/chef/cache/cookbooks/... ================================================================================
errno::enoent
no such file or directory - /var/repository/config.json
i trying load file in ruby_block , perform chef resource actions there, didn't worked. setting parsed config variable , utilize outside of ruby_block didn't work.
ruby_block "load config" block config = json.parse(file.read("/var/repository/config.json")) #node["config"] = config doesn't work - node["config"] not set config.each |job, flags| #do stuff - not work because chef context missing end end end
any thought how read file @ runtime , used parsed values in recipe?
you may find helpful utilize lazy evaluation in scenarios this.
in cases, value attribute cannot known until execution phase of chef-client run. in situation, using lazy evaluation of attribute values can helpful. instead of attribute beingness assigned value, may instead assigned code block.
ruby chef
No comments:
Post a Comment