On Mon, Aug 31, 2009 at 6:56 AM, Andrew Heagle <[email protected]> wrote:

>
> Hi,
>
> We want to use files to set variables in some recipes in puppet, which
> works
> ok. However I have one problem. The first step of the recipe is to get
> an
> updated version of a "control file", which has some info to manage
> data.


Is this data that you are assigning to the node or is it data that is
being generated from some intrinsic properties of the node?  Assigned
data should be
expressed using
a function on the Puppetmaster, generated data should be expressed as
fact.  Either way the variable assignment will happen
before the catalog is generated and sent down to the client.  This sounds
like dynamic data that is being assigned so the data source should just
exist on the Puppetmaster and thusly you should use a function.

 Even
> though the file has new data, the recipe reads the file contents only
> when it
> first runs and ignores any changes to the file later. This also
> prevents the recipe from running if the file doesn't exist yet (but
> would when the file gets downloaded).
>

The function approach above should obviate the need to worry about order
here.


> So, this is what happens. There is a class which is assigned to the
> puppet
> master node. The class has an exec resource "download" which downloads
> the latest
> version of the file (from SVN) and a definition which is subscribed to
> the
> Exec. The definition uses the file function to assign the contents of
> the file to
> a variable. When the class gets executed, the file functions in the
> definition
>

So you do use a function... just not a custom one that pulls the most up to
date data file from svn.


> seems to assign the file contents to the variable before the Exec
> "download" in
> the class, so the first time it runs it has the old data still.
>

Exec runs on the client after the catalog is compiled and after all the
functions have been evaluated.  You are introducing an ordering dependency
that is not necessary.  If a function requires new data or an updated data
source, then the function should make sure that it has the latest data.  A
custom function that does an svn up before it sets variables would give you
the behavior that you want.

>
> Any tips on how I can handle this?
>

So here is a link to the custom function page on the wiki:

http://reductivelabs.com/trac/puppet/wiki/WritingYourOwnFunctions

Requires some Ruby but is pretty straight forward.

If you need to insert variables into a specific scope that can be
accomplished as well, but it is a bit more nuanced.  Here is a link to a
thread about a data loading function with example code:

http://groups.google.com/group/puppet-users/browse_thread/thread/b439cd34803ed5a1


> Thanks,
> Andrew
> >
>
Hope this helps,Teyo

-- 
Teyo Tyree :: www.reductivelabs.com :: +1.615.275.5066

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to