How can I get Chef to error or at least report a missing variable in an .erb template?

120 Views Asked by At

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

There are 1 best solutions below

1
On

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