0

I have a module core and a class core::logrotate defined in core/manifests/logrotate.pp.

class core::logrotate {
#...some stuff here
#
  define confd ($ensure = "present" , $log_name = "dummy" ) {
    if ( $ensure == present )
    {
        file {
          "/etc/logrotate.d/$log_name":
            ensure => present,
            source => filelookup("core/${log_name}.logrotate"),
        }
    } else {
        file {
          "/etc/logrotate.d/$log_name":
           ensure => absent,
        }
    }
  }  
}

calling this function inside of templates.pp as

core::logrotate::confd { "mkill": log_name => mkill }

This fails with the error

Error 400 on SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type core::logrotate::confd

If the puppet master version is 2.6.x then this fails, to make it work there used to be a import "*" in the init.pp of the module. Now removed this as moving to puppet 2.7.20.

The code pasted here works in 2.7 but fails in 2.6. Any idea why? how can I make it work for both 2.6 and 2.7?

1 Answer 1

3

You should take the define outside of the class, see the style guide: http://docs.puppetlabs.com/guides/style_guide.html#classes

Also, I think that you might be using modules wrong, it would be much more logical to have a 'logrotate' module on its own.

So; in modulepath/logrotate/manifests/confd.pp you'd put this:

define logrotate::confd ($ensure = "present" , $log_name = "dummy" ) {
  if ( $ensure == present )
  {
    file {
      "/etc/logrotate.d/$log_name":
        ensure => present,
        source => filelookup("core/${log_name}.logrotate"),
    }
  } else {
    file {
      "/etc/logrotate.d/$log_name":
       ensure => absent,
    }
  }
}

That should make it work properly.

Greetings, Ger

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.