defined types question

40 views
Skip to first unread message

Drew

unread,
Jan 9, 2015, 4:51:28 PM1/9/15
to puppet...@googlegroups.com
I'm fooling around with some defined types and am struggling a little.  The following is just a small example of what I'm doing while I work it out:

#/etc/puppet/modules/testmodule/manifests/init.pp
define testmodule ( $message ){
  testmodule::down { "${name}":
     message => "test message for ${name}",
  }

}

#/etc/puppet/modules/testmodule/manifests/down.pp
define testmodule::down (
  $message = "This is a test",
){
        notify { "$name":
                message => "$message"
        }
}


And I'm calling it like:

  testmodule { "$filename":
    message => $message,
  }


I have it included in my site.pp but I keep getting this:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class testmodule for puptest.domain.com on node puptest.domain.com
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run


Google provides no solutions to this that I've been able to discover thus far.  Any help would be appreciated.  I'm sure it's some lack of understanding on my part.

Thanks!

Christopher Wood

unread,
Jan 10, 2015, 8:39:13 AM1/10/15
to puppet...@googlegroups.com
On Fri, Jan 09, 2015 at 01:51:28PM -0800, Drew wrote:
> I'm fooling around with some defined types and am struggling a little.
>  The following is just a small example of what I'm doing while I work it
> out:
> #/etc/puppet/modules/testmodule/manifests/init.pp
> define testmodule ( $message ){
>   testmodule::down { "${name}":
>      message => "test message for ${name}",
>   }
> }

I think init.pp has to contain only the class with the same name as the module.

https://docs.puppetlabs.com/learning/modules1.html#module-structure
https://docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html#example

You'd have to put the first define in another file is all.

> #/etc/puppet/modules/testmodule/manifests/down.pp
> define testmodule::down (
>   $message = "This is a test",
> ){
>         notify { "$name":
>                 message => "$message"
>         }
> }
> And I'm calling it like:
>   testmodule { "$filename":
>     message => $message,
>   }

(You'll get other interesting errors if $filename is not defined anywhere.)

> I have it included in my site.pp but I keep getting this:
> Error: Could not retrieve catalog from remote server: Error 400 on SERVER:
> Could not find class testmodule for [1]puptest.domain.com on
> node [2]puptest.domain.com
> Warning: Not using cache on failed catalog
> Error: Could not retrieve catalog; skipping run
> Google provides no solutions to this that I've been able to discover thus
> far.  Any help would be appreciated.  I'm sure it's some lack of
> understanding on my part.
> 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 [3]puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> [4]https://groups.google.com/d/msgid/puppet-users/7b9505ce-1383-42ff-8f00-e28e86353000%40googlegroups.com.
> For more options, visit [5]https://groups.google.com/d/optout.
>
> References
>
> Visible links
> 1. http://puptest.ironmountain.com/
> 2. http://puptest.ironmountain.com/
> 3. mailto:puppet-users...@googlegroups.com
> 4. https://groups.google.com/d/msgid/puppet-users/7b9505ce-1383-42ff-8f00-e28e86353000%40googlegroups.com?utm_medium=email&utm_source=footer
> 5. https://groups.google.com/d/optout

Drew

unread,
Jan 11, 2015, 6:06:28 PM1/11/15
to puppet...@googlegroups.com, christop...@pobox.com
Thanks for jumping in.  I've seen example modules from the forge that have the define in the init.pp.  I'm pretty sure the module can have a define in it or a class. But I am doing something wrong for sure.  I've already tried putting it in a different file and that didn't make any difference.

Christopher Wood

unread,
Jan 11, 2015, 6:31:11 PM1/11/15
to puppet...@googlegroups.com
I could swear that at some point I had a define in init.pp and it worked. For some reason I could not reproduce that when I tried your example.

You might try two things:


1) on your puppet master, try applying site.pp

puppet apply --debug --modulepath /etc/puppet/modules /etc/puppet/manifests/site.pp

That might give you some hints in better error messages.


2) debug on both master and agent if the above works

Master:

su - -c /bin/bash puppet
puppet master --debug --no-daemonize

Agent:

puppet agent --debug --no-daemonize --onetime

Those might give you some better error messages at least.

On Sun, Jan 11, 2015 at 03:06:28PM -0800, Drew wrote:
> Thanks for jumping in.  I've seen example modules from the forge that have
> the define in the init.pp.  I'm pretty sure the module can have a define
> in it or a class. But I am doing something wrong for sure.  I've already
> tried putting it in a different file and that didn't make any difference.
> On Saturday, January 10, 2015 at 8:39:13 AM UTC-5, Christopher Wood wrote:
>
> On Fri, Jan 09, 2015 at 01:51:28PM -0800, Drew wrote:
> >    I'm fooling around with some defined types and am struggling a
> little.
> >     The following is just a small example of what I'm doing while I
> work it
> >    out:
> >    #/etc/puppet/modules/testmodule/manifests/init.pp
> >    define testmodule ( $message ){
> >      testmodule::down { "${name}":
> >         message => "test message for ${name}",
> >      }
> >    }
>
> I think init.pp has to contain only the class with the same name as the
> module.
>
> [1]https://docs.puppetlabs.com/learning/modules1.html#module-structure
> [2]https://docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html#example
>
> You'd have to put the first define in another file is all.
>
> >    #/etc/puppet/modules/testmodule/manifests/down.pp
> >    define testmodule::down (
> >      $message = "This is a test",
> >    ){
> >            notify { "$name":
> >                    message => "$message"
> >            }
> >    }
> >    And I'm calling it like:
> >      testmodule { "$filename":
> >        message => $message,
> >      }
>
> (You'll get other interesting errors if $filename is not defined
> anywhere.)
>
> >    I have it included in my site.pp but I keep getting this:
> >    Error: Could not retrieve catalog from remote server: Error 400 on
> SERVER:
> >    Could not find class testmodule for [1][3]puptest.domain.com on
> >    node [2][4]puptest.domain.com
> >    Warning: Not using cache on failed catalog
> >    Error: Could not retrieve catalog; skipping run
> >    Google provides no solutions to this that I've been able to
> discover thus
> >    far.  Any help would be appreciated.  I'm sure it's some lack of
> >    understanding on my part.
> >    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 [5]puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> [6]https://groups.google.com/d/msgid/puppet-users/c8217b76-8628-4f44-9a95-b11ddc258f10%40googlegroups.com.
> For more options, visit [7]https://groups.google.com/d/optout.
>
> References
>
> Visible links
> 1. https://docs.puppetlabs.com/learning/modules1.html#module-structure
> 2. https://docs.puppetlabs.com/puppet/latest/reference/modules_fundamentals.html#example
> 3. http://puptest.domain.com/
> 4. http://puptest.domain.com/
> 5. mailto:puppet-users...@googlegroups.com
> 6. https://groups.google.com/d/msgid/puppet-users/c8217b76-8628-4f44-9a95-b11ddc258f10%40googlegroups.com?utm_medium=email&utm_source=footer
> 7. https://groups.google.com/d/optout

Felix Frank

unread,
Jan 11, 2015, 6:46:20 PM1/11/15
to puppet...@googlegroups.com
On 01/10/2015 02:39 PM, Christopher Wood wrote:
> On Fri, Jan 09, 2015 at 01:51:28PM -0800, Drew wrote:
>> > I'm fooling around with some defined types and am struggling a little.
>> > The following is just a small example of what I'm doing while I work it
>> > out:
>> > #/etc/puppet/modules/testmodule/manifests/init.pp
>> > define testmodule ( $message ){
>> > testmodule::down { "${name}":
>> > message => "test message for ${name}",
>> > }
>> > }
> I think init.pp has to contain only the class with the same name as the module.

Kind of like that, but backwards :-)

The class 'testmodule' must reside in init.pp. Any class or define *can*
be put there and the autoloader will find it all right. But it is better
practice to put everything in their own respective files.

The issue here is likely that the OP tries to `include testmodule` even
though there is no such class. Just get rid of this include statement -
instantiating your define will Just Work.

HTH,
Felix

Drew

unread,
Jan 12, 2015, 7:57:05 AM1/12/15
to puppet...@googlegroups.com
Damn!  That was it.  Removed my include and it works exactly like it should.

Drew

unread,
Jan 12, 2015, 7:57:39 AM1/12/15
to puppet...@googlegroups.com
Thanks, Felix.
Reply all
Reply to author
Forward
0 new messages