Reputation: 138
I'm trying to create a chef script which downloads a file & pass the content of the downloaded file to template variables using IO.read(downloaded File), which internally download multiple files. Downloaded file has a specific format such as filename, url, checksum, etc. I need to make use of remote_file again inside template based on the data of the first remote_file.
Since the remote file doesn't exist, I get a compile time error
Errno::ENOENT
-------------
No such file or directory @ rb_sysopen - ....
Any suggestions to solve my use case?
Upvotes: 0
Views: 268
Reputation: 54267
You need to delay the file read until converge time due to the two-pass model. Read https://coderanger.net/two-pass/ for details on what the two-pass model is. In this case you probably want something like variables foo: lazy { IO.read('something') }
(assuming you are running Chef 13).
Upvotes: 1