renaud
2012-Sep-05 10:09 UTC
[Puppet Users] Weird variable dependency issue + different behavior between master/masterless
Hello all, I know that execution order is not guaranteed within a scope without explicitly declaring dependencies. However I''ve always been able to set variables in classes, and expect them to be used properly in templates that I declare in a File statement in the same class. It looks like I came across a problem with this yesterday : My class contains : $master_port = 6379 $master_host = $hostname ? { /(stage|live)-xx([a-d])-redis1/ => "$1-yy$2-redis1", default => false, } file { "/etc/redis/redis.conf": ensure => file, owner => "root", group => "root", mode => "0644", content => template("redis/redis.conf.erb"), } And redis.conf.erb contains : <% if master_host -%> slaveof <%= master_host %> <%= master_port %> <% end -%> When the hostname matches the regexp, here''s what I get in redis.conf depending on how I run puppet : - If I run puppet masterless using "puppet apply testing.pp" (with testing.pp being a simple manifest that just include the module that contains the class above) : "slaveof live-yya-redis1 6379" This is fine - But if I run puppet through "puppet agent --test", with the exact same manifest on the puppetmaster as locally, I get this : "slaveof 6379" So, it looks like in the second case the master_host variable is definitely set (otherwise the if statement in the .erb would exit), but set to an empty string, while the other master_port variable, which is defined right next to it in the manifest, works fine ! Any idea why that should be ? Thanks ! -- 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/-/Ve4XJQIpfFYJ. 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.
jcbollinger
2012-Sep-05 14:01 UTC
[Puppet Users] Re: Weird variable dependency issue + different behavior between master/masterless
On Wednesday, September 5, 2012 5:09:52 AM UTC-5, renaud wrote:> > Hello all, > > I know that execution order is not guaranteed within a scope without > explicitly declaring dependencies. > However I''ve always been able to set variables in classes, and expect them > to be used properly in templates that I declare in a File statement in the > same class. >Indeed you should be able to rely on that, for the correct definition of "properly".> It looks like I came across a problem with this yesterday : > > My class contains : > > $master_port = 6379 > $master_host = $hostname ? { > /(stage|live)-xx([a-d])-redis1/ => "$1-yy$2-redis1", > default => false, > } > > file { "/etc/redis/redis.conf": > ensure => file, > owner => "root", > group => "root", > mode => "0644", > content => template("redis/redis.conf.erb"), > } > > And redis.conf.erb contains : > > <% if master_host -%> > slaveof <%= master_host %> <%= master_port %> > <% end -%> > > When the hostname matches the regexp, here''s what I get in redis.conf > depending on how I run puppet : > > - If I run puppet masterless using "puppet apply testing.pp" (with > testing.pp being a simple manifest that just include the module that > contains the class above) : > "slaveof live-yya-redis1 6379" > This is fine > - But if I run puppet through "puppet agent --test", with the exact same > manifest on the puppetmaster as locally, I get this : > "slaveof 6379" > > So, it looks like in the second case the master_host variable is > definitely set (otherwise the if statement in the .erb would exit), but set > to an empty string, while the other master_port variable, which is defined > right next to it in the manifest, works fine ! > > Any idea why that should be ? >The Puppet templating docs recommend referring to DSL variables via Ruby class variables, so as @master_host and @master_port in your case. Referring to them via local variables (as your template does) will often work, but it can fail in interesting ways if your variables happen to have the same name as in-scope local variables of the Puppet application. I think that''s what has happened to you. I suspect that the conflicting master_* variables belong to the puppet master code (makes sense), so it is plausible that they are not in scope when you apply your class via "puppet apply", whereas they are in scope when the template is processed by the master in order to service "puppet agent". John -- 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/-/AbYxW9qErd0J. 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.
renaud
2012-Sep-05 14:19 UTC
[Puppet Users] Re: Weird variable dependency issue + different behavior between master/masterless
Thanks John, The Puppet templating docs recommend referring to DSL variables via Ruby> class variables, so as @master_host and @master_port in your case. > Referring to them via local variables (as your template does) will often > work, but it can fail in interesting ways if your variables happen to have > the same name as in-scope local variables of the Puppet application. I > think that''s what has happened to you. >Indeed I''ve seen this since posting and started addressing my variables with @. This didn''t help unfortunately.> > I suspect that the conflicting master_* variables belong to the puppet > master code (makes sense), so it is plausible that they are not in scope > when you apply your class via "puppet apply", whereas they are in scope > when the template is processed by the master in order to service "puppet > agent". > > ... and I also thought of this, so I prepended "redis_" in front of myvariable names. Unfortunately this still didn''t help. To clarify, my template now looks like this : <% if @redis_master_host -%> slaveof <%= @redis_master_host %> <%= @redis_master_port %> <% end -%> -- 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/-/WOa4y3ENoH4J. 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.
renaud
2012-Sep-05 14:24 UTC
[Puppet Users] Re: Weird variable dependency issue + different behavior between master/masterless
I should add that I''ve added a ''notice'' statement for debugging, which again shows the correct things when the manifest is applied manually, but doesn''t seem to be executed (at all) when run through the puppetmaster On Wednesday, September 5, 2012 3:19:07 PM UTC+1, renaud wrote:> > Thanks John, > > The Puppet templating docs recommend referring to DSL variables via Ruby >> class variables, so as @master_host and @master_port in your case. >> Referring to them via local variables (as your template does) will often >> work, but it can fail in interesting ways if your variables happen to have >> the same name as in-scope local variables of the Puppet application. I >> think that''s what has happened to you. >> > > Indeed I''ve seen this since posting and started addressing my variables > with @. > This didn''t help unfortunately. > > >> >> I suspect that the conflicting master_* variables belong to the puppet >> master code (makes sense), so it is plausible that they are not in scope >> when you apply your class via "puppet apply", whereas they are in scope >> when the template is processed by the master in order to service "puppet >> agent". >> >> ... and I also thought of this, so I prepended "redis_" in front of my > variable names. Unfortunately this still didn''t help. > To clarify, my template now looks like this : > > <% if @redis_master_host -%> > slaveof <%= @redis_master_host %> <%= @redis_master_port %> > <% end -%> > > >-- 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/-/VGtWq84BqWkJ. 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.
renaud
2012-Sep-05 15:20 UTC
[Puppet Users] Re: Weird variable dependency issue + different behavior between master/masterless
I''ve found the problem ! "$1-yy$2-redis1" just didn''t work on the puppetmaster, it needs better escaping : ""${1}-yy${2}-redis1" I''d still be interested to know the reason for that, and also why my ''notice'' statement had no output when run from puppetmaster. On Wednesday, September 5, 2012 3:24:10 PM UTC+1, renaud wrote:> > I should add that I''ve added a ''notice'' statement for debugging, which > again shows the correct things when the manifest is applied manually, but > doesn''t seem to be executed (at all) when run through the puppetmaster > > On Wednesday, September 5, 2012 3:19:07 PM UTC+1, renaud wrote: >> >> Thanks John, >> >> The Puppet templating docs recommend referring to DSL variables via Ruby >>> class variables, so as @master_host and @master_port in your case. >>> Referring to them via local variables (as your template does) will often >>> work, but it can fail in interesting ways if your variables happen to have >>> the same name as in-scope local variables of the Puppet application. I >>> think that''s what has happened to you. >>> >> >> Indeed I''ve seen this since posting and started addressing my variables >> with @. >> This didn''t help unfortunately. >> >> >>> >>> I suspect that the conflicting master_* variables belong to the puppet >>> master code (makes sense), so it is plausible that they are not in scope >>> when you apply your class via "puppet apply", whereas they are in scope >>> when the template is processed by the master in order to service "puppet >>> agent". >>> >>> ... and I also thought of this, so I prepended "redis_" in front of my >> variable names. Unfortunately this still didn''t help. >> To clarify, my template now looks like this : >> >> <% if @redis_master_host -%> >> slaveof <%= @redis_master_host %> <%= @redis_master_port %> >> <% end -%> >> >> >>-- 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/-/IBMdE03E1D4J. 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.
R.I.Pienaar
2012-Sep-05 15:38 UTC
Re: [Puppet Users] Re: Weird variable dependency issue + different behavior between master/masterless
----- Original Message -----> From: "renaud" <renaud@renaudguerin.net> > To: puppet-users@googlegroups.com > Sent: Wednesday, September 5, 2012 4:20:17 PM > Subject: [Puppet Users] Re: Weird variable dependency issue + different behavior between master/masterless > > I''ve found the problem ! > "$1-yy$2-redis1" just didn''t work on the puppetmaster, it needs > better escaping : " "${1}-yy${2}-redis1" > > > I''d still be interested to know the reason for that, and also why my > ''notice'' statement had no output when run from puppetmaster. >are the agents and masters the same version? There was some change in behavior between some versions wrt to -''s in variable names, you should always fo "${foo}" inside quotes -- 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.
renaud
2012-Sep-05 15:42 UTC
Re: [Puppet Users] Re: Weird variable dependency issue + different behavior between master/masterless
That was the problem indeed. The agent was 2.7.19 and the master 2.7.14. Thanks ! On Wednesday, September 5, 2012 4:38:58 PM UTC+1, R.I. Pienaar wrote:> > > > ----- Original Message ----- > > From: "renaud" <ren...@renaudguerin.net <javascript:>> > > To: puppet...@googlegroups.com <javascript:> > > Sent: Wednesday, September 5, 2012 4:20:17 PM > > Subject: [Puppet Users] Re: Weird variable dependency issue + different > behavior between master/masterless > > > > I''ve found the problem ! > > "$1-yy$2-redis1" just didn''t work on the puppetmaster, it needs > > better escaping : " "${1}-yy${2}-redis1" > > > > > > I''d still be interested to know the reason for that, and also why my > > ''notice'' statement had no output when run from puppetmaster. > > > > are the agents and masters the same version? There was some change in > behavior > between some versions wrt to -''s in variable names, you should always fo > "${foo}" inside quotes >-- 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/-/CUHNNDoL_s0J. 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.