Andrew Heagle
2009-Aug-31 13:56 UTC
[Puppet Users] "Dynamically" use file contents in variables
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. 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). 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 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. Any tips on how I can handle this? Thanks, Andrew --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Teyo Tyree
2009-Sep-01 00:20 UTC
[Puppet Users] Re: "Dynamically" use file contents in variables
On Mon, Aug 31, 2009 at 6:56 AM, Andrew Heagle <logaan777@gmail.com> 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 puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---