Hi,
I’m looking for some general help here as a chef n00b. I’m getting hung up
while writing recipes with logic because I don’t know how to test my cases.
For instance, in bash if I were going to write some lines that test for a
variable or parses command output I’ll drop to the shell, run the command or
set the variable, test, and verify I’m getting what I expect, then drop back
into vi and write to that output. I’m getting lost while writing recipes
because I don’t know how to do this (and maybe I shouldn’t)
For example, I have a recipe that I want to test if an attribute is set, if
set do something, else, do something else. I know I can do:
if node.tomcat.attribute?(“folder”)
do some stuff
else
do some other stuff
end
But what I don’t know is how to test that attribute first, before committing
that to a recipe. Generally, for ruby scripting, I do that in IRB. Was
kind of hoping shef would provide that for me but I can’t get it to work
like I think it should (and/or don’t understand how it should so I can
change the way I do things). Another case might be verifying that an
attribute has been overridden as expected.
I’ve tried dumping attributes from a node with ‘knife node show
-F json > somefile.json’ and then launching shef and importing those ‘shef
-j somefile.json’ but I still don’t seem to be able to access my attributes.
I’ve tried ‘become_node’ but limited success with that.
I’m not really seeking tech support here. More I’d like to hear from the
people who are knee deep in chef every day. Is shef the IRB of Chef as I
assumed it was? Do you know of any “best practices” guides or how-tos for
writing recipes and the best tools/environment settings for doing so? Am I
completely off in left field (aka, I’m looking at this all wrong)?
Thanks,
Mike G.