file resource to provide serveral files

66 views
Skip to first unread message

Andreas Dvorak

unread,
Jan 24, 2014, 8:25:53 AM1/24/14
to puppet...@googlegroups.com
Dear all,

with my class config.pp I would like to provide config file to /etc/logrotate.d.

filename: config.pp
class logrotate::config($conf_file){
  case $::osfamily {
    redhat:{
      file { "/etc/logrotate.d/${conf_file}":
        ensure => 'present',
        owner  => 'root',
        group  => 'root',
        mode   => '0644',
        source => "puppet://${puppetmaster}/modules/logrotate/${conf_file}",
      }
    }
    solaris:{
      notice('logrotate not available')
    }
    default:{
      fail("Unsupported platform: ${::osfamily}")
    }
  }
}

In the nodes.pp I have
  class {'logrotate::config':
    conf_file => 'test',
  }

but I get the error
Duplicate declaration: Class[Logrotate::Config]

I also have this in a module
      class {'logrotate::config':
        conf_file => 'puppet',
      }

I thought the title of the file resource is different and it should work.
As far as I know this problem can be solved by "define" or "virtual resource", but I have no idea what is a good solution.
Can you please help me?

Best regards
Andreas

Jose Luis Ledesma

unread,
Jan 24, 2014, 8:37:20 AM1/24/14
to puppet...@googlegroups.com
I think that what you need is a define here.

Regards,

Andreas Dvorak

unread,
Jan 24, 2014, 9:39:45 AM1/24/14
to puppet...@googlegroups.com
Hi,

I am trying this. config.pp of module logrotate
define logrotate::config{

  case $::osfamily {
    redhat:{
      file { "/etc/logrotate.d/${conf_file}":
        ensure => 'present',
        owner  => 'root',
        group  => 'root',
        mode   => '0644',
        source => "puppet://${puppetmaster}/modules/logrotate/${conf_file}",
      }
    }
    solaris:{
      notice('logrotate not available')
    }
    default:{
      fail("Unsupported platform: ${::osfamily}")
    }
  }
}

in the nodes.pp
  logrotate::config{'test':}
  logrotate::config{'puppet':}

And it says
Duplicate declaration: File[/etc/logrotate.d/] is already declared in file /data/git/test/modules/logrotate/manifests/config.pp:10
It also does not work if I just have on file to provide. The it does nothing.


Can you please help me?
Andreas


Henrique Rodrigues

unread,
Jan 24, 2014, 9:44:50 AM1/24/14
to puppet...@googlegroups.com
You're trying to define File[/etc/logrotate.d/$conf_file], buf if
$conf_file is missing or empty, Puppet will create
File[/etc/logrotate.d/] instead. This might explain your error.

Best regards,
Henrique Rodrigues

Jose Luis Ledesma

unread,
Jan 24, 2014, 10:41:36 AM1/24/14
to puppet...@googlegroups.com
Instead of $conf_file you should use $title or $name inside the define


Regards,

Andreas Dvorak

unread,
Jan 27, 2014, 3:17:42 AM1/27/14
to puppet...@googlegroups.com
Hi,

thank you now it is working.

Best regards,
Andreas
Reply all
Reply to author
Forward
0 new messages