FAQ
Hi,

I am learning puppet using version 2.7.18 on a fresh ubuntu install.

I am trying to test this module
https://github.com/liamjbennett/puppet-sabnzbd/blob/master/manifests/init.ppbut I'm having trouble with the
if defined(Class['supervisor::service']) section in that it doesn't get run
even though the supervisor module is installed.

If i put "else{ notice("supervisor not defined?") }" on the end then I see
that notice msg in the 'puppet apply --debug' output.

This supervisor module is downloaded/installed OK from Puppet Forge and if
I either

a) comment out the 'if defined' then it works as expected
b) *change the if *defined(Class['supervisor::service']) to read if defined(
'supervisor::service') then it also works as expected.

As you can see there is an "include supervisor" at top of the class which
I'm guessing isn't being called in the
order needed for the 'if defined' to work and the one without the Class[ ]
must work because puppet auto loads the modules from the modulepath
and checks if that namespace and module exist?

This is all new to me so i could be very wrong but can anyone explain given
that init.pp why the 'if defined' isn't working and what is the best
way to achieve what the 'if defined' is there for and that's to see if the
supervisor module is installed/loaded before entering the if statement and
using the module?

Many thanks for reading
fLo



--
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+unsubscribe@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Ellison Marks at Aug 19, 2013 at 6:24 pm
    So, I can't speak to the authors intentions, but I'll do my best to explain
    the behavior.

    As you guessed defined() behaves differently based on what is passed to it.
    If passed a resource reference, as it is in the module, it will check that
    that resource has been declared. if passed a string, it will treat it as a
    type/class name and make sure that the resource has been defined. So, as
    written, it's checking if a class by the name of supervisor::service has
    been declared, while the way you write it, it check if anything by the name
    of supervisor::service has been defined.

    The 'include supervisor' you noticed does nothing regarding this error, as
    the type in question is supervisor::service.

    If I had to guess, at one point in the past, supervisor::service was a
    class, while it is now a defined type, and the module you're working with
    hasn't updated or something.
    On Monday, August 19, 2013 8:33:09 AM UTC-7, Florian Gray Jones wrote:

    Hi,

    I am learning puppet using version 2.7.18 on a fresh ubuntu install.

    I am trying to test this module
    https://github.com/liamjbennett/puppet-sabnzbd/blob/master/manifests/init.ppbut I'm having trouble with the
    if defined(Class['supervisor::service']) section in that it doesn't get
    run even though the supervisor module is installed.

    If i put "else{ notice("supervisor not defined?") }" on the end then I see
    that notice msg in the 'puppet apply --debug' output.

    This supervisor module is downloaded/installed OK from Puppet Forge and
    if I either

    a) comment out the 'if defined' then it works as expected
    b) *change the if *defined(Class['supervisor::service']) to read if
    defined('supervisor::service') then it also works as expected.

    As you can see there is an "include supervisor" at top of the class which
    I'm guessing isn't being called in the
    order needed for the 'if defined' to work and the one without the Class[] must work because puppet auto loads the modules from the modulepath
    and checks if that namespace and module exist?

    This is all new to me so i could be very wrong but can anyone explain
    given that init.pp why the 'if defined' isn't working and what is the best
    way to achieve what the 'if defined' is there for and that's to see if the
    supervisor module is installed/loaded before entering the if statement and
    using the module?

    Many thanks for reading
    fLo


    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Florian Gray Jones at Aug 20, 2013 at 3:32 am
    ok, that's great. Thanks for the help.

    The puppet-docs it says: "*Modules are how Puppet finds the classes and
    types it can use* — it automatically loads any class<http://docs.puppetlabs.com/puppet/2.7/reference/lang_classes.html>
      or defined type<http://docs.puppetlabs.com/puppet/2.7/reference/lang_defined_types.html> stored
    in its modules."

    With this in mind, if "*if *defined(Class[ ])" checks for classes.. and in
    my case 'supervisor::service' is as you mentioned not a class but a define.
    Is there an equivalent like "if defined(Define[ ])" or is best practice to
    continue using "if defined('supervisor::service')" to just check for
    anything of that name.

    Thanks again
    fLo


    On Monday, 19 August 2013 23:33:09 UTC+8, Florian Gray Jones wrote:

    Hi,

    I am learning puppet using version 2.7.18 on a fresh ubuntu install.

    I am trying to test this module
    https://github.com/liamjbennett/puppet-sabnzbd/blob/master/manifests/init.ppbut I'm having trouble with the
    if defined(Class['supervisor::service']) section in that it doesn't get
    run even though the supervisor module is installed.

    If i put "else{ notice("supervisor not defined?") }" on the end then I see
    that notice msg in the 'puppet apply --debug' output.

    This supervisor module is downloaded/installed OK from Puppet Forge and
    if I either

    a) comment out the 'if defined' then it works as expected
    b) *change the if *defined(Class['supervisor::service']) to read if
    defined('supervisor::service') then it also works as expected.

    As you can see there is an "include supervisor" at top of the class which
    I'm guessing isn't being called in the
    order needed for the 'if defined' to work and the one without the Class[] must work because puppet auto loads the modules from the modulepath
    and checks if that namespace and module exist?

    This is all new to me so i could be very wrong but can anyone explain
    given that init.pp why the 'if defined' isn't working and what is the best
    way to achieve what the 'if defined' is there for and that's to see if the
    supervisor module is installed/loaded before entering the if statement and
    using the module?

    Many thanks for reading
    fLo


    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ellison Marks at Aug 20, 2013 at 4:38 am
    Since in this case, it's checking that supervisor::service exists so it can
    declare one, I'd say checking for just 'supervisor::service' would be fine.
    You may want to stay around and see what other people think though, as I
    could be missing something.

    Looking at it again, the check to see if a class has been declared seems
    really odd... and testing it now that I have a second, it doesn't actually
    seem to work at all. I'm not sure how idiomatic that is, or was, but maybe
    someone else can shed some light on it.
    On Monday, August 19, 2013 8:32:39 PM UTC-7, Florian Gray Jones wrote:

    ok, that's great. Thanks for the help.

    The puppet-docs it says: "*Modules are how Puppet finds the classes and
    types it can use* — it automatically loads any class<http://docs.puppetlabs.com/puppet/2.7/reference/lang_classes.html>
    or defined type<http://docs.puppetlabs.com/puppet/2.7/reference/lang_defined_types.html> stored
    in its modules."

    With this in mind, if "*if *defined(Class[ ])" checks for classes.. and
    in my case 'supervisor::service' is as you mentioned not a class but a
    define. Is there an equivalent like "if defined(Define[ ])" or is best
    practice to continue using "if defined('supervisor::service')" to just
    check for anything of that name.

    Thanks again
    fLo


    On Monday, 19 August 2013 23:33:09 UTC+8, Florian Gray Jones wrote:

    Hi,

    I am learning puppet using version 2.7.18 on a fresh ubuntu install.

    I am trying to test this module
    https://github.com/liamjbennett/puppet-sabnzbd/blob/master/manifests/init.ppbut I'm having trouble with the
    if defined(Class['supervisor::service']) section in that it doesn't get
    run even though the supervisor module is installed.

    If i put "else{ notice("supervisor not defined?") }" on the end then I
    see that notice msg in the 'puppet apply --debug' output.

    This supervisor module is downloaded/installed OK from Puppet Forge and
    if I either

    a) comment out the 'if defined' then it works as expected
    b) *change the if *defined(Class['supervisor::service']) to read if
    defined('supervisor::service') then it also works as expected.

    As you can see there is an "include supervisor" at top of the class which
    I'm guessing isn't being called in the
    order needed for the 'if defined' to work and the one without the Class[] must work because puppet auto loads the modules from the modulepath
    and checks if that namespace and module exist?

    This is all new to me so i could be very wrong but can anyone explain
    given that init.pp why the 'if defined' isn't working and what is the best
    way to achieve what the 'if defined' is there for and that's to see if
    the supervisor module is installed/loaded before entering the if statement
    and using the module?

    Many thanks for reading
    fLo


    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jcbollinger at Aug 20, 2013 at 1:40 pm

    On Monday, August 19, 2013 10:32:39 PM UTC-5, Florian Gray Jones wrote:
    ok, that's great. Thanks for the help.

    The puppet-docs it says: "*Modules are how Puppet finds the classes and
    types it can use* — it automatically loads any class<http://docs.puppetlabs.com/puppet/2.7/reference/lang_classes.html>
    or defined type<http://docs.puppetlabs.com/puppet/2.7/reference/lang_defined_types.html> stored
    in its modules."
    Where did you see that? Although true, it may be a bit misleading to new
    Puppeteers, as "load" in this context does not mean the same thing as
    "declare". That is, the classes in installed modules are not automatically
    assigned to any node; you must still declare them for the nodes where you
    want them.


    With this in mind, if "*if *defined(Class[ ])" checks for classes.. and
    in my case 'supervisor::service' is as you mentioned not a class but a
    define. Is there an equivalent like "if defined(Define[ ])" or is best
    practice to continue using "if defined('supervisor::service')" to just
    check for anything of that name.
    The expression "defined(Class[<classname>])" checks for the named class
    being already declared for the target node. The expression
    "defined(<classname>)" on the other hand, checks whether a class or
    resource type is known to Puppet, so that it is *available* to be declared
    for the target node. The form you suggest, "defined(Define[<title>])" does
    not make sense, but the either the condition "defined(Supervisor::Service['
    sabnzbd'])" or the condition "defined 'supervisor::service'" should work,
    depending on which you mean (they are not equivalent).

    Now, having said all that, I leave you with one more piece of advice: don't
    do it. The usual use of the defined() function, wherein its argument is a
    resource reference, introduce a parse-order dependency into your manifest
    set, and that's bad news for you. The other form, where you test for a
    class or resource type being available, is less problematic, but usually
    not what you want. It is rarely the case that the desired response to a
    resource type or class being undefined is anything other than catalog
    compilation failure, and you don't need defined() for that.


    John

    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedAug 19, '13 at 4:05p
activeAug 20, '13 at 1:40p
posts5
users3
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase