Hey all,
Came across a situation tonight that I wanted to get feedback on. I've
got some standard patterns I use for dealing with TRUE one-time run
recipes.
A concrete example was from my previous employer was something like this:
- spin up node of role "fooapp" with additional recipe "fooapp::bootstrap"
- at the end of the run, the "fooapp::bootstrap" recipe removes itself
from the runlist for that node like so
ruby_block "remove_bootstrap_recipe" do
block do
Chef::
Log.info("Removing fooapp boostrap from runlist")
node.run_list.remove("recipe[fooapp::bootstrap]") if
node.run_list.include?("recipe[fooapp::bootstrap]")
end
action :create
end
This works fine but now it was always cumbersome to tell folks
"initially the runlist is THIS but afterwards the runlist will be
THAT". I've been thinking about ways to make this more data-driven.
The thought I was having is relying on something that I previously
maligned - bootstrapping nodes not saving until the complete run is
done. I'm thinking now I can leverage that functionality to include a
::bootstrap recipe from any cookbook.
Can anyone see any downsides in this? The general idea is something
like (in fooapp::default):
existence = search("node", "name:#{node.name}")
# Do some stuff that should always run/check
# At the end of fooapp::default
include_recipe "fooapp::bootstrap" if existence.size == 0
Does anyone see a problem with this? Is there a convenience method
that can tell me if I'm bootstrapping that I'm just not aware of?
Again, the end goal is to NOT need to specify the commensurate
"bootstrap" recipe for a given cookbook on setup.
Right now I'm actually dealing with a private cloud setup where I
don't have access to a userdata construct so I need to do some similar
to that, reload ohai and continue with the bootstrap. My concern is
accidentally calling node.save and having things blow up. I want this
to be as simple and durable as possible.
Thoughts?