[chef] compile vs execution phase


Chronological Thread 
  • From: Bill Warner < >
  • To:
  • Subject: [chef] compile vs execution phase
  • Date: Fri, 3 Jan 2014 22:46:22 -0700

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...
done similar to:

#attributes file
default[: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" )
  end
end

#recipe
node[:cassandra][:data_dirs].each do |data_dir|
  directory "#{data_dir}" do
    owner "cassandra"
    group "cassandra"
    mode 0750
    action :create
    recursive true
  end
end


Of 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.

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.

Thanks for any help
--
Bill Warner



Archive powered by MHonArc 2.6.16.

§