Ryan Schwartz
2006-Aug-05 00:14 UTC
[Puppet-users] PATCH: provide replace parameter for sourced files
Following patch for pfile.rb and pfile/source.rb allows the user to set a replace => false parameter on a file sourced by puppet, but not replaced if checksums do not match. This is for cases in which it is desired to distribute initial "bootstrap" files and ensure future existence, yet allow them to be modified on the node. RTS --- pfile.rb~ Wed Aug 2 04:47:05 2006 +++ pfile.rb Sat Aug 5 04:59:11 2006 @@ -113,6 +113,12 @@ end end + newparam(:replace) do + desc "Whether or not to replace a file that is + sourced but exists" + defaultto true + end + newparam(:ignore) do desc "A parameter which omits action on files matching specified patterns during recursion. Uses Ruby''s builtin globbing --- pfile/source.rb~ Sat Aug 5 06:58:53 2006 +++ pfile/source.rb Sat Aug 5 06:59:25 2006 @@ -120,6 +120,12 @@ @is = :absent end + # if replace => false then fake the checksum so that the file + # is not overwritten. + if FileTest.exists?(@parent[:path]) and ! @parent [:replace] + @is = @stats[:checksum] + end + @should = [@stats[:checksum]] # If we''re a directory, then do not copy anything, and instead just # create the directory using the ''create'' state. -- Ryan Schwartz Director of Systems Operations Joyent, Inc. TextDrive, Inc.
Matthew Palmer
2006-Aug-05 00:45 UTC
[Puppet-users] PATCH: provide replace parameter for sourced
On Sat, Aug 05, 2006 at 02:14:46AM -0500, Ryan Schwartz wrote:> Following patch for pfile.rb and pfile/source.rb allows the user to > set a replace => false parameter on a file sourced by puppet, but not > replaced if checksums do not match. This is for cases in which it is > desired to distribute initial "bootstrap" files and ensure future > existence, yet allow them to be modified on the node.Totally. Cool. Feature. Some comments:> --- pfile.rb~ Wed Aug 2 04:47:05 2006 > +++ pfile.rb Sat Aug 5 04:59:11 2006 > @@ -113,6 +113,12 @@ > end > end > + newparam(:replace) do > + desc "Whether or not to replace a file that is > + sourced but exists"I think some extra description here, roughly equivalent to what you wrote above, would be handy. It might be a bit hard to work out exactly what the purpose of this parameter is otherwise, from a quick glance. Also, I''m unclear from your description as to whether a file that exists but doesn''t match the checksum of the source will result in a warning or not -- I can imagine there would be times that you''d want to have the warning, and other times you wouldn''t. Perhaps a better solution might be an ifexists parameter, that defaults to ''replace'' but could also be ''warn'' or ''ok''/''donothing''/''ignore'' (not sure which of those sounds better). Alternately the ensure parameter could be extended, but I think that''s overloaded enough already with symlink destinations. Probably best if this all goes into a ticket in Trac, so the patches and discussion can be Trac''d (heh). Also, any test cases? If you''re not into that sort of thing, let me know and I''ll write them (I need more practice at unit testing Puppet anyway). - Matt -- The main advantages of Haynes and Chilton manuals are that they cost $15, where the factory manuals cost $100 and up, and that they will tell you how to use two hammers, a block of wood, and a meerkat to replace "special tool no. 2-112-A" -- Matt Roberds in asr.
Luke Kanies
2006-Aug-06 12:28 UTC
[Puppet-users] PATCH: provide replace parameter for sourced
On Aug 5, 2006, at 2:45 AM, Matthew Palmer wrote:> On Sat, Aug 05, 2006 at 02:14:46AM -0500, Ryan Schwartz wrote: >> Following patch for pfile.rb and pfile/source.rb allows the user to >> set a replace => false parameter on a file sourced by puppet, but not >> replaced if checksums do not match. This is for cases in which it is >> desired to distribute initial "bootstrap" files and ensure future >> existence, yet allow them to be modified on the node. > > Totally. Cool. Feature.I''ve been thinking about taking the checks (e.g., ''unless'' and ''onlyif'') from Exec and turning them into metaparams so they worked for all types. This could easily be a similar metacheck, since most exec tests seem to be for file existence.> Some comments: > >> --- pfile.rb~ Wed Aug 2 04:47:05 2006 >> +++ pfile.rb Sat Aug 5 04:59:11 2006 >> @@ -113,6 +113,12 @@ >> end >> end >> + newparam(:replace) do >> + desc "Whether or not to replace a file that is >> + sourced but exists" > > I think some extra description here, roughly equivalent to what you > wrote > above, would be handy. It might be a bit hard to work out exactly > what the > purpose of this parameter is otherwise, from a quick glance. > > Also, I''m unclear from your description as to whether a file that > exists but > doesn''t match the checksum of the source will result in a warning > or not -- > I can imagine there would be times that you''d want to have the > warning, and > other times you wouldn''t. > > Perhaps a better solution might be an ifexists parameter, that > defaults to > ''replace'' but could also be ''warn'' or > ''ok''/''donothing''/''ignore'' (not sure > which of those sounds better). Alternately the ensure parameter > could be > extended, but I think that''s overloaded enough already with symlink > destinations.I agree; multiple values is appropriate. ''true/warn/ignore'', or something like that.> Probably best if this all goes into a ticket in Trac, so the > patches and > discussion can be Trac''d (heh). Also, any test cases? If you''re > not into > that sort of thing, let me know and I''ll write them (I need more > practice at > unit testing Puppet anyway).I concur with both of these -- tests are good, and so is Trac. -- Luke Kanies http://madstop.com 615-594-8199