[Puppet Users] Variable Scoping = Root Canal
I've been struggling with puppet variable scope all day, well, for several months actually. I think I have pretty simple requirements. For any given node, I want to be able to set a series of variables and include a set of classes, based on three different aspects of a node, being physical location, operating system, and function. If I try and do this with classes, I find that variables set in a class included from a node, are not visible to other classes included from that node. node 'node1.fr.xxx.com' { include facility::sjc include ldap::client } In this example, variables defined in facility::sjc are not visible in ldap::client (in this case, it would be the IP address of the local LDAP server). Another approach is to do everything with node inheritance, but in order to model these three functions, you end up with nodes with names like sjcDellBootServer or nycVmwareBootServer, which is just plain stupid. So... what am I missing here, and why is such a simple thing so complicated in puppet? I'm not even sure if this email is lucid. I am really annoyed and frustrated as hell. 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-us...@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Re: [Puppet Users] Variable Scoping = Root Canal
I think you could do: node 'node1.fr.xxx.com' { include facility::sjc $my_ldap_server = $facility::sjc::ldap_server include ldap::client } On Sun, Jun 27, 2010 at 2:02 AM, Douglas Garstang wrote: > I've been struggling with puppet variable scope all day, well, for > several months actually. > > I think I have pretty simple requirements. For any given node, I want > to be able to set a series of variables and include a set of classes, > based on three different aspects of a node, being physical location, > operating system, and function. If I try and do this with classes, I > find that variables set in a class included from a node, are not > visible to other classes included from that node. > > node 'node1.fr.xxx.com' { > include facility::sjc > include ldap::client > } > > In this example, variables defined in facility::sjc are not visible in > ldap::client (in this case, it would be the IP address of the local > LDAP server). > > Another approach is to do everything with node inheritance, but in > order to model these three functions, you end up with nodes with names > like sjcDellBootServer or nycVmwareBootServer, which is just plain > stupid. > > So... what am I missing here, and why is such a simple thing so > complicated in puppet? I'm not even sure if this email is lucid. I am > really annoyed and frustrated as hell. > > 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-us...@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-us...@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Re: [Puppet Users] Variable Scoping = Root Canal
On Sun, Jun 27, 2010 at 11:28 AM, Steve Neuharth wrote: > I think you could do: > > node 'node1.fr.xxx.com' { > include facility::sjc > $my_ldap_server = $facility::sjc::ldap_server > include ldap::client > } That seems to work. Not pretty though. I'll go see if it causes any other problems, apart from rubbing my logical brain the wrong way. Thanks. 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-us...@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Re: [Puppet Users] Variable Scoping = Root Canal
Yup, I hear ya. This was a pain until I realized that the only variables defined in nodes are inherited from node to node. The variables defined in classes that are included by the node must be expressed using the variable's full context. I just ended up mapping certain variables to other variables in my server templates and it seems to work fine. Modules will invariably use different variable names for the same information so it seems like this kind of duct tape is unavoidable. --steev tel: (612) 840-6253 On Jun 27, 2010, at 1:39 PM, Douglas Garstang wrote: > On Sun, Jun 27, 2010 at 11:28 AM, Steve Neuharth > wrote: >> I think you could do: >> >> node 'node1.fr.xxx.com' { >> include facility::sjc >> $my_ldap_server = $facility::sjc::ldap_server >> include ldap::client >> } > > That seems to work. Not pretty though. I'll go see if it causes any > other problems, apart from rubbing my logical brain the wrong way. > Thanks. > > 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-us...@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en > . > -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-us...@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Re: [Puppet Users] Variable Scoping = Root Canal
On Sun, 27 Jun 2010, Douglas Garstang wrote: > node 'node1.fr.xxx.com' { > include facility::sjc > include ldap::client > } > > In this example, variables defined in facility::sjc are not visible in > ldap::client (in this case, it would be the IP address of the local > LDAP server). I'd probably use extlookup(), but you could try something like this (untested): node 'node1.fr.xxx.com' { $facility_name = "sjc" include ldap::client } class facility { $ldapserver = undef # this gets overridden in facility::sjc } class facility::myfacility { include "facility::${facility_name}" } class facility::sjc extends facility { $facility::ldapserver = "1.2.3.4" } class ldap_client { include facility::myfacility ... do something with $facility::ldapserver } > Another approach is to do everything with node inheritance Common opinion seems to be that node inheritance should be avoided. --apb (Alan Barrett) -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-us...@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Re: [Puppet Users] Variable Scoping = Root Canal
On Mon, Jun 28, 2010 at 4:07 AM, Alan Barrett wrote: > On Sun, 27 Jun 2010, Douglas Garstang wrote: >> node 'node1.fr.xxx.com' { >> include facility::sjc >> include ldap::client >> } >> >> In this example, variables defined in facility::sjc are not visible in >> ldap::client (in this case, it would be the IP address of the local >> LDAP server). > > I'd probably use extlookup(), but you could try something like this > (untested): > > node 'node1.fr.xxx.com' { > $facility_name = "sjc" > include ldap::client Not gonna work. It's pointless to define the facility at the node level. 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-us...@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Re: [Puppet Users] Variable Scoping = Root Canal
On Mon, 28 Jun 2010, Douglas Garstang wrote: > >node 'node1.fr.xxx.com' { > >$facility_name = "sjc" > >include ldap::client > > Not gonna work. It's pointless to define the facility at the node level. You have to set the facility name somewhere. If not at the node level, then where? Also, if you were willing to put "include facility::sjc" at the node level, then why is "$facility_name = sjc" any worse? I am unlikely to help you any further, unless there's a dramatic improvement in your attitude, and your ability to adapt examples to your own use cases. --apb (Alan Barrett) -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-us...@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Re: [Puppet Users] Variable Scoping = Root Canal
This actually looks like a prime candidate for a custom written fact so that you don't have to faff about like this all over the place. On 28/06/2010 17:28, Alan Barrett wrote: > On Mon, 28 Jun 2010, Douglas Garstang wrote: >>>node 'node1.fr.xxx.com' { >>>$facility_name = "sjc" >>>include ldap::client >> Not gonna work. It's pointless to define the facility at the node level. > You have to set the facility name somewhere. If not at the node level, > then where? > > Also, if you were willing to put "include facility::sjc" at the node > level, then why is "$facility_name = sjc" any worse? > > I am unlikely to help you any further, unless there's a dramatic > improvement in your attitude, and your ability to adapt examples to your > own use cases. > > --apb (Alan Barrett) > -- Trevor Hemsley Infrastructure Engineer . * C A L Y P S O * Brighton, UK OFFICE +44 (0) 1273 666 350 FAX +44 (0) 1273 666 351 . www.calypso.com This electronic-mail might contain confidential information intended only for the use by the entity named. If the reader of this message is not the intended recipient, the reader is hereby notified that any dissemination, distribution or copying is strictly prohibited. * P * /*/ Please consider the environment before printing this e-mail /*/ -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-us...@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Re: [Puppet Users] Variable Scoping = Root Canal
On Mon, Jun 28, 2010 at 9:28 AM, Alan Barrett wrote: > On Mon, 28 Jun 2010, Douglas Garstang wrote: >> > node 'node1.fr.xxx.com' { >> > $facility_name = "sjc" >> > include ldap::client >> >> Not gonna work. It's pointless to define the facility at the node level. > > You have to set the facility name somewhere. If not at the node level, > then where? Further up the node/class hierarchy where I don't have to duplicate it for every node. > > Also, if you were willing to put "include facility::sjc" at the node > level, then why is "$facility_name = sjc" any worse? I'm not prepared to do that. > > I am unlikely to help you any further, unless there's a dramatic > improvement in your attitude, and your ability to adapt examples to your > own use cases. Just stating the facts. 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-us...@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.