FAQ
So...

I was just reading the new puppet scoping documentation at
http://docs.puppetlabs.com/guides/scope_and_puppet.html.

I don't get it. If I have this...

class web_server {
include common
include webserver
$my_role = "web_server"
}

Can I access the $my_role variable in the webserver class?

Doug.

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Search Discussions

  • Llowder at Aug 10, 2012 at 8:42 pm

    On Friday, August 10, 2012 3:28:33 PM UTC-5, Douglas wrote:
    So...

    I was just reading the new puppet scoping documentation at
    http://docs.puppetlabs.com/guides/scope_and_puppet.html.

    I don't get it. If I have this...

    class web_server {
    include common
    include webserver
    $my_role = "web_server"
    }

    Can I access the $my_role variable in the webserver class?
    If you use: $web_server::my_role

    Doug.
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/4qMMmWYJtVsJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Douglas Garstang at Aug 10, 2012 at 8:52 pm

    On Fri, Aug 10, 2012 at 1:42 PM, llowder wrote:
    On Friday, August 10, 2012 3:28:33 PM UTC-5, Douglas wrote:

    So...

    I was just reading the new puppet scoping documentation at
    http://docs.puppetlabs.com/guides/scope_and_puppet.html.

    I don't get it. If I have this...

    class web_server {
    include common
    include webserver
    $my_role = "web_server"
    }

    Can I access the $my_role variable in the webserver class?

    If you use: $web_server::my_role
    This seems completely screwed to me. What if your in a general class,
    one not necessarily related to the function of a web server (but still
    included from a web server), and you need to access the role?

    Doug.

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Llowder at Aug 10, 2012 at 9:24 pm

    On Friday, August 10, 2012 3:52:42 PM UTC-5, Douglas wrote:
    On Fri, Aug 10, 2012 at 1:42 PM, llowder <llow...@gmail.com <javascript:>>
    wrote:
    On Friday, August 10, 2012 3:28:33 PM UTC-5, Douglas wrote:

    So...

    I was just reading the new puppet scoping documentation at
    http://docs.puppetlabs.com/guides/scope_and_puppet.html.

    I don't get it. If I have this...

    class web_server {
    include common
    include webserver
    $my_role = "web_server"
    }

    Can I access the $my_role variable in the webserver class?

    If you use: $web_server::my_role
    This seems completely screwed to me. What if your in a general class,
    one not necessarily related to the function of a web server (but still
    included from a web server), and you need to access the role?
    Then use the fully qualified variable name as I mentioned in my last post.


    Doug.
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/WT9kA4LHTvYJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Douglas Garstang at Aug 10, 2012 at 9:28 pm

    On Fri, Aug 10, 2012 at 2:24 PM, llowder wrote:
    On Friday, August 10, 2012 3:52:42 PM UTC-5, Douglas wrote:
    On Fri, Aug 10, 2012 at 1:42 PM, llowder wrote:

    On Friday, August 10, 2012 3:28:33 PM UTC-5, Douglas wrote:

    So...

    I was just reading the new puppet scoping documentation at
    http://docs.puppetlabs.com/guides/scope_and_puppet.html.

    I don't get it. If I have this...

    class web_server {
    include common
    include webserver
    $my_role = "web_server"
    }

    Can I access the $my_role variable in the webserver class?

    If you use: $web_server::my_role
    This seems completely screwed to me. What if your in a general class,
    one not necessarily related to the function of a web server (but still
    included from a web server), and you need to access the role?
    Then use the fully qualified variable name as I mentioned in my last post.
    What if the class I am in doesn't KNOW that the parent is $web_server ...?

    Doug.

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Denmat at Aug 10, 2012 at 10:10 pm

    On 11/08/2012, at 7:27, Douglas Garstang wrote:
    On Fri, Aug 10, 2012 at 2:24 PM, llowder wrote:

    On Friday, August 10, 2012 3:52:42 PM UTC-5, Douglas wrote:
    On Fri, Aug 10, 2012 at 1:42 PM, llowder wrote:

    On Friday, August 10, 2012 3:28:33 PM UTC-5, Douglas wrote:

    So...

    I was just reading the new puppet scoping documentation at
    http://docs.puppetlabs.com/guides/scope_and_puppet.html.

    I don't get it. If I have this...

    class web_server {
    include common
    include webserver
    $my_role = "web_server"
    }

    Can I access the $my_role variable in the webserver class?

    If you use: $web_server::my_role
    This seems completely screwed to me. What if your in a general class,
    one not necessarily related to the function of a web server (but still
    included from a web server), and you need to access the role?
    Then use the fully qualified variable name as I mentioned in my last post.
    What if the class I am in doesn't KNOW that the parent is $web_server ...?

    Doug.
    What if you've declared my_role in several classes? This provides certainty. Alternatively you could make a fact that has the value you want of my_role and reference that in the top scope $::my_role.

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Dan White at Aug 10, 2012 at 11:19 pm

    On Aug 10, 2012, at 6:11 PM, Denmat wrote:


    On 11/08/2012, at 7:27, Douglas Garstang wrote:
    On Fri, Aug 10, 2012 at 2:24 PM, llowder wrote:

    On Friday, August 10, 2012 3:52:42 PM UTC-5, Douglas wrote:
    On Fri, Aug 10, 2012 at 1:42 PM, llowder wrote:

    On Friday, August 10, 2012 3:28:33 PM UTC-5, Douglas wrote:

    So...

    I was just reading the new puppet scoping documentation at
    http://docs.puppetlabs.com/guides/scope_and_puppet.html.

    I don't get it. If I have this...

    class web_server {
    include common
    include webserver
    $my_role = "web_server"
    }

    Can I access the $my_role variable in the webserver class?

    If you use: $web_server::my_role
    This seems completely screwed to me. What if your in a general class,
    one not necessarily related to the function of a web server (but still
    included from a web server), and you need to access the role?
    Then use the fully qualified variable name as I mentioned in my last post.
    What if the class I am in doesn't KNOW that the parent is $web_server ...?

    Doug.
    What if you've declared my_role in several classes? This provides certainty. Alternatively you could make a fact that has the value you want of my_role and reference that in the top scope $::my_role.
    It is called: "Making an honest attempt to help you avoid shooting your own toes off".

    By forcing you to specifically reference the class name along with the variable name (that includes the top scope $::foo), it saves you extensive grief down the road when you eventually end up with the same variable name in multiple classes.

    Or would you rather have to track all the variable names in all the classes you use (the ones you write yourself along with ones you pull from places like the Puppet Forge) to ensure unique variable names ?


    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Mark Roggenkamp at Aug 11, 2012 at 2:25 pm
    You may want to consider making whatever needs $my_role into a define or
    class that can be used in another module. Then make a module to contain
    roles. These roles would be classes (since puppet has no role resources
    type like this) that include relevant defines/classes from other modules.
    I've found for my use cases composing things that way works a bit better,
    though of course YMMV.

    Regards,
    Mark
    On Friday, August 10, 2012 4:28:33 PM UTC-4, Douglas wrote:

    So...

    I was just reading the new puppet scoping documentation at
    http://docs.puppetlabs.com/guides/scope_and_puppet.html.

    I don't get it. If I have this...

    class web_server {
    include common
    include webserver
    $my_role = "web_server"
    }

    Can I access the $my_role variable in the webserver class?

    Doug.
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/_6R6QOKDXugJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • James Sweeny at Aug 11, 2012 at 2:39 pm
    Parameterized classes were also made for this issue, but I don't recommend
    going that route if you have several levels of classes being included
    before you have to use the variable.

    You might find it worthwhile to set $my_role in Hiera, and provide a sane
    default within the webserver class.
    On Sat, Aug 11, 2012 at 10:24 AM, Mark Roggenkamp wrote:

    You may want to consider making whatever needs $my_role into a define or
    class that can be used in another module. Then make a module to contain
    roles. These roles would be classes (since puppet has no role resources
    type like this) that include relevant defines/classes from other modules.
    I've found for my use cases composing things that way works a bit better,
    though of course YMMV.

    Regards,
    Mark
    On Friday, August 10, 2012 4:28:33 PM UTC-4, Douglas wrote:

    So...

    I was just reading the new puppet scoping documentation at
    http://docs.puppetlabs.com/**guides/scope_and_puppet.html<http://docs.puppetlabs.com/guides/scope_and_puppet.html>.


    I don't get it. If I have this...

    class web_server {
    include common
    include webserver
    $my_role = "web_server"
    }

    Can I access the $my_role variable in the webserver class?

    Doug.
    --
    You received this message because you are subscribed to the Google Groups
    "Puppet Users" group.
    To view this discussion on the web visit
    https://groups.google.com/d/msg/puppet-users/-/_6R6QOKDXugJ.

    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to
    puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/puppet-users?hl=en.


    --

    James Sweeny
    Professional Services
    http://puppetlabs.com/

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedAug 10, '12 at 8:28p
activeAug 11, '12 at 2:39p
posts9
users6
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase