I believe the answer you are looking for is the environment attribute that the Hash object expects.
See http: //docs.opscodecode/chef/resources.html#arguments and https://github.com/opscode/chef/commit/96ef7d770a7d898fdce097c7fda9039abf7bf485
To set up a custom environment variable, you should write the following
my_env_vars = {"env1" => "val1", "env2" => "val2"} cron "env" do environment my_env_vars command "/path/to/job -someoption" end
The chef will iterate over your hash, and you should see the following in sudo crontab -e
Quick note: on my machine with a chef 10.16.2 passing the hash directly to the cron stanza will return a syntax error. syntax error, unexpected tASSOC, expecting '}' Not that you passed in the hash anyway, but I thought it was worth mentioning, as someone else could repeat my same error. Once you throw the hash into a variable, everything works as expected.
source share