Hi guys, I''m trying to get my head around conditionals and variables. What I''m trying to do now is to distinguish between puppet servers and puppet clients and deliver some settings differently. How can I do that? I tried to put a variable in the node classes: node ''puppet1'' { $puppetmode = "master", include puppetmasterclass } node ''client1'' { $puppetmode = "client", include puppetclientclass } and then in the classes do something like: case $puppetmode { "master": { $baseurl_base = "file:///puppet/repos" } "client": { $baseurl_base = "http://puppet1/inst" } } class system::repos { yumrepo { ''RHEL-5.5-64'': descr => ''RedHat Enterprise Linux 5.5 64-bit'', baseurl => "${baseurl_base}/RHEL-5.5-x86_64/Server", } } But that doesn''t work. Another attempt was to do the "case" statement by hostname wildcard: case $hostname { "puppet*" { $baseurl_base = "..." } } but that didn''t work either. It''s not only about puppet master/client. I will have to know in some modules in which datacentre a given node is, etc. So was hoping to be able to set a couple of parameters in the node declaration and then work with that in the modules. Can I somehow pass variables or other tokens around the catalogue and make conditional decisions in other modules based on them? I''m sure this is something trivial but can''t figure out how to do that. Thanks for any hints! GiBo -- 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.
Hi, general: it would be nice if you could also send logoutput. On 05/03/2011 08:34 AM, Giovanni Bordello wrote:> Hi guys, > > I''m trying to get my head around conditionals and variables. > > What I''m trying to do now is to distinguish between puppet servers and > puppet clients and deliver some settings differently. How can I do that? > > I tried to put a variable in the node classes: > > node ''puppet1'' { > $puppetmode = "master", > include puppetmasterclass > } > node ''client1'' { > $puppetmode = "client", > include puppetclientclass > }I would not use the colon on the line with the key value pair.> > and then in the classes do something like: > > case $puppetmode { > "master": { > $baseurl_base = "file:///puppet/repos" > } > "client": { > $baseurl_base = "http://puppet1/inst" > } > } > class system::repos { > yumrepo { ''RHEL-5.5-64'': > descr => ''RedHat Enterprise Linux 5.5 64-bit'', > baseurl => "${baseurl_base}/RHEL-5.5-x86_64/Server", > } > } > > But that doesn''t work. Another attempt was to do the "case" statement by > hostname wildcard: > > case $hostname { > "puppet*" { > $baseurl_base = "..." > } > }using regexp requires another syntax for the hostname: /^puppet*$/ instead of "puppet*"> > but that didn''t work either. > > It''s not only about puppet master/client. I will have to know in some > modules in which datacentre a given node is, etc. So was hoping to be > able to set a couple of parameters in the node declaration and then work > with that in the modules. > > Can I somehow pass variables or other tokens around the catalogue and > make conditional decisions in other modules based on them? > > I''m sure this is something trivial but can''t figure out how to do that. > > Thanks for any hints! > > GiBo > > > > >-- 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.
> Can I somehow pass variables or other tokens around the catalogue and > make conditional decisions in other modules based on them?Excellent question. You more or less can, but you shouldn''t. Scoping issues will bite you sooner or later. For your use case, you should take a hard look at Custom Facts. HTH, Felix -- 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.
On Wed, May 4, 2011 at 8:01 AM, Felix Frank <felix.frank@alumni.tu-berlin.de> wrote:> > Can I somehow pass variables or other tokens around the catalogue and > > make conditional decisions in other modules based on them? > > Excellent question. > > You more or less can, but you shouldn''t. Scoping issues will bite you > sooner or later. >Not if you either set the variables at top scope or always use fully qualified variables in a class that includes all your other classes. Another method to avoid scoping is to set these as node parameters in your node classifier. For your use case, you should take a hard look at Custom Facts. This will avoid any potential scoping issues but does add the overhead of writing the facts. -- 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.