Ugo Bellavance
2014-May-15 19:25 UTC
[Puppet Users] Module for lsyncd - multiple syncs to be configured, but only one config file
Hi,
I wrote my first puppet module and it is for lsyncd. I know that there is
already a module for that but I think it was written to manage lsyncd and
csync2 syncs and I don't really understand everything it it so I can't
really use it or learn from it. I have been able to create a simple
module, below is the code from init.pp (I know, I should modularize it so
that init.pp calls ::install and ::config, but I'll do that once the module
works as I want). It is actually working, but only allows for one sync to
be configured. I'd like it to be able to configure more than one sync, but
since all the configs for lsyncd is in one file, I wouldn't know how to do
it unless I add some variables like $method, $source2, $dest2, $desthost2,
$append2 and $method, $source3, $dest3, $desthost3, $append3, $method,
$sourcex, $destx, $desthostx, $appendx. I think someone here would know how
to do it.
Code for init.pp:
class lsyncd ($method, $source, $dest, $desthost, $append) {
package { 'lsyncd':
ensure => installed,
}
file { 'lsyncd.conf':
ensure => present,
path => '/etc/lsyncd.conf',
owner => root,
group => root,
mode => '0644',
content => template('lsyncd/lsyncd.conf.erb')
}
service { 'lsyncd':
ensure => running,
enable => true,
hasrestart => true,
hasstatus => true,
require => [Package['lsyncd'],
File['lsyncd.conf']],
subscribe =>
File[
'lsyncd.conf'
],
}
}
This is the code for the erb template (feel free to let me know if I you
find errors):
settings {
logfile = "/var/log/lsyncd.log",
statusFile = "/tmp/lsyncd.status",
inotifyMode = "CloseWrite or Modify",
delay = "1"
}
sync {
<%= @method %>,
source = "<%= source %>",
host = "<%= desthost %>",
targetdir = "<%= dest %>",
<% if @append -%>
rsync = {
_extra = {"--append"}
}
<% end -%>
}
Here is how I'd like to have my config file:
settings {
logfile = "/var/log/lsyncd.log",
statusFile = "/tmp/lsyncd.status",
inotifyMode = "CloseWrite or Modify",
delay = "1"
}
sync {
default.rsyncssh,
source = "/var/www/test/src",
host = "www.example.com",
targetdir = "/var/www/test/dst",
rsync = {
_extra = {"--append"}
}
}
sync {
default.rsyncssh,
source = "/var/www/",
host = "www.example.com",
targetdir = "/var/www/test/dst1",
rsync = {
_extra = {"--append"}
}
}
sync {
default.rsyncssh,
source = "/var/log/",
host = "www.example.com",
targetdir = "/var/www/test/dst2",
rsync = {
_extra = {"--append"}
}
}
Thanks,
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to puppet-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/a63e58f0-1da9-40ef-bb4c-b5e99f3b0365%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.