Pieter Barrezeele
2008-May-27 13:07 UTC
[Puppet Users] overriding variables in site manifest
Hi all, Consider this code: site.pp: -- node default { $arrayvar = ["default"] include sampleclass } node hostA extends default { $arrayvar = ["hostA"] } node hostB extends default { $arrayvar = ["hostB"] } -- And sampleclass.pp: -- class sampleclass { info $arrayvar } -- Now, if I''m not mistaken, as both hostA and hostB extend the default node, they inherit the settings for the default node but the value of the $arrayvar should be the values that are defined in the node definition of both hostA and hostB. If I execute this recipe, however, I only see info logging telling me that for both extending nodes, the $arrayvar is still ["default"]... Am I doing something wrong? Kind regards, Pieter. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Meier
2008-May-27 13:29 UTC
[Puppet Users] Re: overriding variables in site manifest
Hi> Now, if I''m not mistaken, as both hostA and hostB extend the default > node, they inherit the settings for the default node but the value of > the $arrayvar should be the values that are defined in the node > definition of both hostA and hostB. > > If I execute this recipe, however, I only see info logging telling me > that for both extending nodes, the $arrayvar is still ["default"]... > > Am I doing something wrong?http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#variable-scope "Classes, components, and nodes introduce a new scope. Puppet is currently dynamically scoped, which means that scope hierarchies are created based on where the code is evaluated instead of where the code is defined." Therefore you will always have the value of the variable defined in the default node. As well please note that inheritance in nodes is different to inheritance in classes (there have been discussion once on the list), which might be as well confusing. My hint is to avoid inheritance in nodes completly and to only do it in classes. If you think that you are still defining too much twice or more, it would be better to switch to an external node tool. greets pete --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Pieter Barrezeele
2008-May-27 13:49 UTC
[Puppet Users] Re: overriding variables in site manifest
On 27 May 2008, at 15:29, Peter Meier wrote:> > Hi > >> Now, if I''m not mistaken, as both hostA and hostB extend the default >> node, they inherit the settings for the default node but the value of >> the $arrayvar should be the values that are defined in the node >> definition of both hostA and hostB. >> >> If I execute this recipe, however, I only see info logging telling me >> that for both extending nodes, the $arrayvar is still ["default"]... >> >> Am I doing something wrong? > > > http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#variable-scope > > "Classes, components, and nodes introduce a new scope. Puppet is > currently dynamically scoped, which means that scope hierarchies are > created based on where the code is evaluated instead of where the code > is defined." > > Therefore you will always have the value of the variable defined in > the > default node. As well please note that inheritance in nodes is > different > to inheritance in classes (there have been discussion once on the > list), > which might be as well confusing.I don''t think that''s correct. Maybe I should have mentioned it in my original post: the behaviour I was sketching does not occur when defining a variable as a string. More specifically: --- node default { $groupdn ="" } node general extends default { include ldapauth } node administration extends default { $groupdn = "cn=AuthorizedUsers,ou=Groups,dc=domain,dc=com" include ldapauth } --- In this case, overriding the value of a variable does work. It seems there''s a difference in the way puppet handles strings and arrays... Regards, Pieter. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Meier
2008-May-27 13:51 UTC
[Puppet Users] Re: overriding variables in site manifest
Hi>>> Now, if I''m not mistaken, as both hostA and hostB extend the default >>> node, they inherit the settings for the default node but the value of >>> the $arrayvar should be the values that are defined in the node >>> definition of both hostA and hostB. >>> >>> If I execute this recipe, however, I only see info logging telling me >>> that for both extending nodes, the $arrayvar is still ["default"]... >>> >>> Am I doing something wrong? >> >> http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#variable-scope >> >> "Classes, components, and nodes introduce a new scope. Puppet is >> currently dynamically scoped, which means that scope hierarchies are >> created based on where the code is evaluated instead of where the code >> is defined." >> >> Therefore you will always have the value of the variable defined in >> the >> default node. As well please note that inheritance in nodes is >> different >> to inheritance in classes (there have been discussion once on the >> list), >> which might be as well confusing. > > I don''t think that''s correct. Maybe I should have mentioned it in my > original post: the behaviour I was sketching does not occur when > defining a variable as a string. > > More specifically: > --- > node default { > $groupdn ="" > } > > node general extends default { > include ldapauth > } > > node administration extends default { > $groupdn = "cn=AuthorizedUsers,ou=Groups,dc=domain,dc=com" > include ldapauth > } > --- > > In this case, overriding the value of a variable does work. It seems > there''s a difference in the way puppet handles strings and arrays...but here you are including in the subcnodes and not the default node. greets Pete --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Pieter Barrezeele
2008-May-27 14:03 UTC
[Puppet Users] Re: overriding variables in site manifest
On 27 May 2008, at 15:51, Peter Meier wrote:>> >> I don''t think that''s correct. Maybe I should have mentioned it in my >> original post: the behaviour I was sketching does not occur when >> defining a variable as a string. >> >> More specifically: >> --- >> node default { >> $groupdn ="" >> } >> >> node general extends default { >> include ldapauth >> } >> >> node administration extends default { >> $groupdn = "cn=AuthorizedUsers,ou=Groups,dc=domain,dc=com" >> include ldapauth >> } >> --- >> >> In this case, overriding the value of a variable does work. It seems >> there''s a difference in the way puppet handles strings and arrays... > > but here you are including in the subcnodes and not the default node.Correct :-) But I know it works even if you''re including in the default node. To return to what you''ve replied to my first post:>> http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#variable-scope >> >> "Classes, components, and nodes introduce a new scope. Puppet is >> currently dynamically scoped, which means that scope hierarchies are >> created based on where the code is evaluated instead of where the >> code >> is defined.">Am I wrong in saying that the configuration for node hostA is evaluated in hostA instead of the default node? It seems to me that as node hostA introduces a new scope, this scope has priority over the default node''s scope... Still, I don''t think this has anything to do with scopes, rather than the way puppet handles single valued variables as opposed to array variables. In the meantime, I also found this: http://reductivelabs.com/trac/puppet/wiki/PuppetIntroduction#arrays "Puppet has very limited support for arrays -- you can create them, and pass them as values, but you can not modify them." So it seems I am stuck, waiting till puppet has a more profound support for arrays, or is this information outdated? greets, Pieter. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---