[chef] Re: Re: compile vs execution phase


Chronological Thread 
  • From: Bill Warner < >
  • To:
  • Subject: [chef] Re: Re: compile vs execution phase
  • Date: Tue, 7 Jan 2014 22:03:51 -0700


In case anyone was on the edge of their seat waiting to see if this all worked.

I was able to add the lazy evaluation to the template creation for the cassandra.yaml and it will add data directories as they exist.  A nice side effect, slap in a new disk, my disks cookbook part/encrypt/mkfs/mounts it, cassandra cookbook adds the mount to the cassandra.yaml and restarts the service.

Also used subscribes as I noted in the example above to the mount[/data/#] to get everything working.  This has kept my disks cookbook as something that can be included and used for other applications.  Mainly hadoop of which I will be working on next.

Thanks for the help,
-BillWa

On Mon, Jan 6, 2014 at 9:55 PM, Bill Warner < " target="_blank"> > wrote:
I started playing with a subscribes and got something functional.  As a mock up I was able to use:

#second recipe in run list
node[:directories].each do |dir|
  directory "#{dir}/cassandra/data" do
    action :nothing
    recursive true
    subscribes :create, "directory[#{dir}]"
  end
end

where node[:directories] was equal to [ "/data/1", "/data/2", "/data/3" ] and it was set and creating the directories in another recipe:

#first in run list
#attributes file to simulate the physical disks being created:
node[:directories] = [ "/data/1", "/data/2", "/data/3" ]

#recipe
node[:directories].each do |dir|
  directory dir do

    action :create
    recursive true
  end
end

I 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

-s



On Sat, Jan 4, 2014 at 12:46 AM, Bill Warner < " target="_blank"> > wrote:
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




--
--
Bill Warner



--
--
Bill Warner



--
--
Bill Warner



Archive powered by MHonArc 2.6.16.

§