Let us say I have some Chef code like:
require 'mixlib/shellout'
yum_package 'somepackage'
myvar = Mixlib::ShellOut.new('/bin/somecommand').run_command.stdout.strip
Where /bin/somecommand
does not exist yet because it is installed by somepackage
. This will fail at recipe compile time for that reason, but will obviously work at convergence time providing the package installs successfully (and if it doesn't then obviously the recipe has failed anyway). This also fails if the package is installed be a previous recipe in the runlist since they are all compiled together upfront. How do I include things in a Chef recipe that that recipe or runlist installs itself?
myvar
there's no real answer, usually I avoid using code evaluation from external commands at compile time unless very necessary to define other resources. In brief, I'd do aruby_block 'set myvar' { node.run_state['myvar'] = Mixlib::ShellOut.[...] }
node.run_state
was exactly what I was looking for - thanks. Make that an answer and I'll accept it!