[chef] Re: What are you guys using dynamic resources for? (was: Notifying Resources within Ruby Block Resource)


Chronological Thread 
  • From: Bryan Baugher < >
  • To:
  • Subject: [chef] Re: What are you guys using dynamic resources for? (was: Notifying Resources within Ruby Block Resource)
  • Date: Tue, 29 Nov 2011 10:59:44 -0600

I ran into a specific case where my application had scripts that handled initialization and configuration, as well as having information that chef needed in order to correctly configure the application. This meant that I had to do this at run time or rather in a chef resource (bash/execute or ruby_block).

Ultimately I chose to use ruby_block out of simplicity, that it felt more like chef to me, it was easier for me, and allowed me to throw errors with information about the error.

I then decided to create dynamic bash/execute blocks because it was simpler then handling bash commands myself, and it helps with auditing to see a resource for every change that is made (especially with chef's json reporting).

I then needed a way to restart my service on any change made and so restarting in the above fashion is simple, chef-like, and helps with auditing.

Bryan

On Mon, Nov 28, 2011 at 5:34 PM, Daniel DeLeo < "> > wrote:


On Monday, November 28, 2011 at 2:46 PM, Bryan Baugher wrote:

> I just ran into this problem myself. It seems that notifications are only handled by Chef::Runner, in which the runner holds the list of notifications (in order to check for duplicates) and only its run_action command can write to the list of notifications.
>
> So when you run, r.run_action you are running the resource without the runner meaning the notification won't be handled.
>
> I spent awhile trying to find a way to inject a resource into the runner's list of resources or get access to the runner itself but for obvious reasons you can't (or it is difficult).
>
> One hack I found that does work is this,
Questions about creating and using resources defined via ruby blocks comes up often enough that I think it's worthwhile to find a more elegant solution, if possible. Can you guys explain what it is you're commonly doing with these?

Off the top of my head, I can see two sorts of scenarios:
1. You need to set a value on a resource during the convergence phase of the Chef run (why?). Adding a means to have lazily evaluated values would be a pretty easy fix.
2. You need to create multiple resources during converge based on some state created by prior actions in the converge phase (again, why?). An elegant solution to this would require a lot more thought.

I know I've asked people about this individually before, but it would be nice to get this on the record and maybe get a feature proposal out of it.

Thanks,

--
Dan DeLeo







Archive powered by MHonArc 2.6.16.

§