29

First off, I apologize for asking such a dumb question. But the reason I ask is because I'm having a hard time finding an answer. I've tried searching Chef's docs, but I have not found a clear explanation.

So what exactly doesChef::Config[:file_cache_path] provide? I've read that its better to use this instead of harding coding a filepath. But what does it evaluate to?

In this particular snippet

newrelic_agent = Chef::Config[:file_cache_path] + '/rewrelic_nginx_agent.tar.gz'


remote_file newrelic_agent do
  source 'http://nginx.com/download/newrelic/newrelic_nginx_agent.tar.gz'
  mode "0744"
end

Thanks in advance.

switchflip
  • 403
  • 1
  • 5
  • 13

1 Answers1

31

The specific value varies by platform and method of install, but that config value defaults to somewhere you can write out temp files. Generally it will be something like /var/chef/cache. This is used for caching cookbooks and files in them, but as you noted you can also use it from your own code for the same kind of thing.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • 3
    Other reasons to not use /tmp would be that some OSes put that on a ramdisk for speed, and some mount it noexec for security. – coderanger Sep 29 '14 at 20:28
  • 1
    Thanks. I was just able to find a good explanation [here](http://docs.getchef.com/config_rb_client.html). – switchflip Sep 29 '14 at 20:31
  • 1
    @StephenKing As someone who's learned a lot of Chef in the last two years, I can't blame the guy. There are multiple versions of the docs on opscode's website alone, and it's not really clear which version is current. To top it off, finding the right page to answer any given question is far from simple. I realize you were at least partially joking, but I'll say I wouldn't have known where in the docs to find it. – Tejay Cardon Sep 29 '14 at 21:19
  • @StephenKing No all of them, but some of them. – switchflip Sep 29 '14 at 21:37
  • 2
    Also /tmp is typically mode 1777 and its better for root-running processes to write to their own directory under /var than to possibly suffer symlink-in-tmp attacks and other badness that is sometimes lurking due to that funky mode bit. The `Chef::Config[:file_cach_path]` should be owned by the process running chef-client and other users should not be able to write to it, which makes it a better choice than /tmp or /var/tmp. – lamont Mar 03 '16 at 04:44
  • 1
    `Chef::Config[:file_cache_path]` with an `e` ;) – KCD May 04 '16 at 00:17