Hi,

I was a little wrong yesterday, you can use hiera, but also you can use a hash in your nodes.pp


class lsync ($sync) {
}

$localsync = {
  instance1 => {
    'source' => 'toto',
    'host' => 'titi',
  },
  instance2 => {
    'source' => 'tutu',
    'host' => 'tata',
  },
}

class {'lsync':
  sync => $localsync
}


Le 15/05/2014 22:40, Poil a écrit :
Hi,

You can use hiera (here a yaml)

sync:
  instance1:
    source: "toto"
    host: "titi
 instance2:
    source: "toto"
    host: "titi

And in your template juste loop on it
<% @sync.each_pair do |name, value| -%>
<%= name %>
   source     = "<%= value['source'] %>",
   host       = "<%= value['host'] %>"
<% end %>

Le 15/05/2014 21:25, Ugo Bellavance a écrit :
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+unsubscr...@googlegroups.com <mailto:puppet-users+unsubscr...@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 <https://groups.google.com/d/msgid/puppet-users/a63e58f0-1da9-40ef-bb4c-b5e99f3b0365%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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 <mailto:puppet-users+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/5375265A.6070702%40quake.fr <https://groups.google.com/d/msgid/puppet-users/5375265A.6070702%40quake.fr?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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/5375B1C8.8020600%40quake.fr.
For more options, visit https://groups.google.com/d/optout.

Reply via email to