0

If I have a line like the below in an .erb:

        TMP_DIR=$(mktemp -d <%= @temp_dir %>/tmp_dir.XXXXXX)

Is there a way I can get Chef to fail, or at least report, if the @temp_dir variable is undefined?

Ideally I'd like to do this with a single call at the top of the recipe, or at the command line with a config option (I'm using chef-client).

Thanks ahead!

1 Answers1

0

You can throw an error and exit Chef with:

Chef::Application.fatal!("Temporary directory is undefined") unless defined? temp_dir

It will not cover empty variable, so you might add temp_dir.empty? check or whatever applies to your case

Szymon
  • 1,525
  • 1
  • 11
  • 12
  • Thanks, but I'm really looking to trigger some sort of strict behavior where no undefined variable use is permitted. I'd like to apply this not only to one variable, but to a mature project with well over 100 templates, and likely thousands of variables, and I can't think of a single use case where an undefined variable should be OK. – Andrew Campbell Nov 30 '18 at 13:18