Jeff
2009-Jul-13 14:39 UTC
[Puppet Users] exec inside a function bombs and kills the puppetmaster
I''m trying to use the puppetmaster to mirror directories. Here''s my function: module Puppet::Parser::Functions ##++ ## function: mirror ## arg[0] user - the login name and corresponding key ## arg[1] host - remote host ## arg[2]: src - local directory ## arg[3]: dest - remote directory ## returns: void ##-- newfunction(:mirror) do |args| user = args[0] host = args[1] src = args[2] dest = args[3] cmd = "/usr/bin/rsync -vaz --delete --delete-during --rsh=\"ssh - i /var/puppet/.ssh/" + user +" -l " + user +"\" " + src + " " + host + ":" + dest exec(cmd) end end This seems pretty straight-forward but the first time I hit this function, the puppetmaster dies and leaves no traces in the logs for troubleshooting the problem. I tested the rsync command and it works fine. Any ideas? BTW: If there''s an easier way to synchronize directories, I''m open to using it. The problem I''ve had in puppet is removing files from dest if they''re removed in the source directory. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thomas Bellman
2009-Jul-13 16:40 UTC
[Puppet Users] Re: exec inside a function bombs and kills the puppetmaster
Jeff wrote:> I''m trying to use the puppetmaster to mirror directories. Here''s my > function:[...]> cmd = "/usr/bin/rsync -vaz --delete --delete-during --rsh=\"ssh - > i /var/puppet/.ssh/" + > user +" -l " + user +"\" " + src + " " + host + ":" + dest > exec(cmd) > end > end > > This seems pretty straight-forward but the first time I hit this > function, the puppetmaster dies and leaves no traces in the logs for > troubleshooting the problem. I tested the rsync command and it works > fine. Any ideas?That''s pretty much expected behaviour if you understand what exec() does. From http://www.ruby-doc.org/core/classes/Kernel.html#M005968 : Replaces the current process by running the given external command. I suspect that what you were really looking for was the system() function. Although doing mirroring in the Puppet *master* doesn''t seem like a particularly good idea at all. Why do you want to do that? Isn''t it better to do that in the client (possibly the client running on the same machine as the master, but still in the client)?> BTW: If there''s an easier way to synchronize directories, I''m open to > using it. The problem I''ve had in puppet is removing files from dest > if they''re removed in the source directory.If the source directory resides on the Puppet master, or on the same machine as the destination and where you are running puppetd, you can do it using the normal file type. If it resides on a different machine, the following definition might help you: # Mirror a directory tree using rsync. define rsync_mirror($source, $target, $sshkey="", $unless="", $onlyif="", $creates="", $month="1-12", $monthday="1-31", $weekday="0-7", $hour="", $minute="", $ensure="present" ) { if $sshkey { $sshcmd = "ssh -i$sshkey" } else { $sshcmd = "ssh" } $rsynccmd = "rsync -aRqv --no-implied-dirs --delete --delete-excluded" $command = "RSYNC_RSH=\"$sshcmd\" $rsynccmd ''$source'' ''$target''" case $ensure { "present": { exec { "$rsynccmd ''$source'' ''$target''": path => "/bin:/usr/bin", unless => $unless ? { "" => undef, default => $unless }, onlyif => $onlyif ? { "" => undef, default => $onlyif }, creates => $creates ? { "" => undef, default => $creates }; } if $hour { cron { "mirror--$title": command => "PATH=/bin:/usr/bin; $command", user => "root", month => $month, monthday => $monthday, weekday => $weekday, hour => $hour, minute => $minute; } } } "absent": { tidy { $target: recurse => true, rmdirs => true, size => 0, backup => false ; } cron { "mirror--$title": command => "PATH=/bin:/usr/bin; $command", ensure => absent; } } default: { fail("Bad rsync_mirror parameter ensure: $ensure") } } } This does an rsync directly, and optionally creates a cron job that continues doing the rsync regularly. That way you don''t need to tie up your normal Puppet runs with the rsync, only the first time. Use it something like this: rsync_mirror { centos-5-x86_64: source => "rsync://my.centos.mirror/CentOS/5/os/x86_64/./", target => "/var/cache/mirrors/centos-5.x86_64/", creates => "/var/cache/mirrors/centos-5.x86_64/images/README", hour => 2, minute => 10; } The month, monthday, weekday, hour and minute parameters control the cron job. The creates, unless and onlyif parameters control if Puppet should run rsync immediately, exactly like the exec type. /Bellman --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Scott Smith
2009-Jul-13 18:28 UTC
[Puppet Users] Re: exec inside a function bombs and kills the puppetmaster
Jeff wrote:> newfunction(:mirror) do |args| > user = args[0] > host = args[1] > src = args[2] > dest = args[3] > cmd = "/usr/bin/rsync -vaz --delete --delete-during --rsh=\"ssh - > i /var/puppet/.ssh/" + > user +" -l " + user +"\" " + src + " " + host + ":" + dest > exec(cmd)You might want to sanitize those parameters before blindly passing them to a shell. -scott -- scott@ohlol.net http://github.com/ohlol --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Kelsey Hightower
2009-Jul-17 20:46 UTC
[Puppet Users] Re: exec inside a function bombs and kills the puppetmaster
I like the idea of having puppet manage a directory by mirroring it using rsync. The function you have seems pretty good, one thing missing is some logging. I have run in to times where you only want to sync on puppetruns and not during a predetermined time period using cron. I normally write scripts that issue a puppetrun for a specific host as part of it''s execution. Also did you every git the mirror function to work? On Jul 13, 2:28 pm, Scott Smith <sc...@ohlol.net> wrote:> Jeff wrote: > > newfunction(:mirror) do |args| > > user = args[0] > > host = args[1] > > src = args[2] > > dest = args[3] > > cmd = "/usr/bin/rsync-vaz --delete --delete-during --rsh=\"ssh - > > i /var/puppet/.ssh/" + > > user +" -l " + user +"\" " + src + " " + host + ":" + dest > > exec(cmd) > > You might want to sanitize those parameters before blindly passing them > to a shell. > > -scott > > -- > sc...@ohlol.net > > http://github.com/ohlol--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---