#recipeI started playing with a subscribes and got something functional. As a mock up I was able to use:
#second recipe in run listnode[:directories].each do |dir|where node[:directories] was equal to [ "/data/1", "/data/2", "/data/3" ] and it was set and creating the directories in another recipe:
directory "#{dir}/cassandra/data" do
action :nothing
recursive true
subscribes :create, "directory[#{dir}]"
end
end
#first in run list#attributes file to simulate the physical disks being created:node[:directories] = [ "/data/1", "/data/2", "/data/3" ]
node[:directories].each do |dir|
directory dir do
action :create
recursive true
end
endI still have to work on the template code and figure out how I can get everything to it. but I am getting closer. I will try to implemet this into my real cookbooks tomorrow.
--On Mon, Jan 6, 2014 at 5:24 PM, Bill Warner < " target="_blank"> > wrote:
I haven't been able to get back to this yet, but I was thinking I may be able to have one resource subscribe to the creation resources from the other cookbook so when they do something it gets kicked off in the first. That way it would negate the need to predefine the loops. I may play with this some tonight or maybe tomorrow.
--On Mon, Jan 6, 2014 at 8:03 AM, Sean OMeara < " target="_blank"> > wrote:
This problem comes up almost every day for me.What needs to happen is.. recipe A needs to converge before recipe B compiles.You can manually manipulate run_contexts if you're brave enough to go mucking around in Chef internals..or...There is a library cookbook called "now" on the community site that provides a hack for you.Check out the integration tests for a usage example-sOn Sat, Jan 4, 2014 at 12:46 AM, Bill Warner < " target="_blank"> > wrote:
Is there a better way to create the directories? I think I can use the lazy attribute assignment to make my template work, but the directory creation is giving me hell.done similar to:I've been working on learning how to write cookbooks using chef-solo. I have created two cookbooks, one that evaluates the physical array controllers and configures, partitions, luks_encrypts, mkfs and mounts the drives to /data/1, /data/2, /data/3, etc... This works really well on a new machine and puts the hardware in a state we are looking for no matter how many drives there are or what their sizes are.I also have a simple cassandra cookbook that installs an fpm version of cassandra, runs a template of the cassandra.yaml and creates the data directories depending on what drives are mounted to /data/1 /data/2 /data/3 etc...
#attributes filedefault[:datadirs] = []Dir.foreach("/data") do |drives|next if drives.match(/^\.\.?$)if system "/bin/mountpoint /data/#{drives}>/dev/null" then
default[:cassandra][:data_dirs].push( "/data/#{drives}/cassandra/data" )endend#recipenode[:cassandra][:data_dirs].each do |data_dir|
directory "#{data_dir}" doowner "cassandra"group "cassandra"mode 0750action :createOf course this is getting generated at compile time when nothing is in /data. The disks cookbook runs and populates /data/# however, the cassandra cookbook wont work unless there is a way to regen the recipe after the disk cookbook has completed. running chef-solo a second time gets things into a proper state.
recursive true
end
end
Thanks for any help--
Bill Warner
--
Bill Warner
--
Bill Warner
Archive powered by MHonArc 2.6.16.