On 05/15/2014 09:25 PM, Ugo Bellavance wrote:
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.


I would suggest you to take a look at concat module.

You can basically split your single config file into multiple parts, and write a defined type for sync sections. For example:

  # smb.conf
  concat { 'lsyncd.conf':
    path    => '/etc/lsyncd.conf',
    owner   => root,
    group   => root,
    mode    => '0644',
  }

  ::concat::fragment { 'lsyncd.conf:settings':
    target  => 'lsyncd.conf',
    content => template('lsyncd/settings.conf.erb'),
    order   => '100',
  }

And write your own defined type, for example:

define lsycnd::sync (
  $method,
  $source,
  $host,
  $targetdir,
) {

  include ::lsyncd

  ::concat::fragment { "lsyncd.conf:sync:${title}":
    target  => 'lsyncd.conf',
    content => template('lsyncd/sync.conf.erb'),
    order   => '200',
  }

}

Now, your sync.conf.erb would look like:

sync {
   <%= @method %>,
   source     = "<%= source %>",
   host       = "<%= desthost %>",
   targetdir  = "<%= dest %>",

<% if @append -%>
   rsync      = {
      _extra = {"--append"}
   }
<% end -%>
}









--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/53753595.8050105%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to