Reputation: 16930
I am trying to read a file content after executing a class GetContentsAPI, basically this class GetContentsAPI will write into the file /etc/api/token.
class Main{
require GetContentsAPI
file("/etc/api/token")
}
When I did the above steps, its says Evaluation Error: Error while evaluating a Function Call, Could not find any files from /etc/api
. Not sure how to make sure the file is already created before trying to read.
Thanks James
Upvotes: 0
Views: 676
Reputation: 180103
The file()
function reads the contents of a file during catalog building. You don't present any details of class GetContentsApi
, but all of the standard puppet facilities that write to files (especially, but not limited to, File
resources) write during catalog application. Unless you've cooked up something highly customized, the file()
function will always read before GetContentsApi
writes.
Moreover, in a master / agent setup (which is the only kind supported in current Puppet), catalog building happens on the master, whereas catalog application happens on the target node, which is usually a different machine, so you're unlikely even to be able to read what was written during a previous catalog-building run.
Also, file()
just returns the file contents as a string, so it's not very useful to call it without using the return value somehow.
It's not at all clear what you're trying to achieve, but from what I can see, you are not going in a fruitful direction. Perhaps you should take a step back and ask a different question about that.
Upvotes: 2