I have a template for zabbix_agentd.conf.erb that has the following line in it: <% if has_variable?( "mysqlsrv" ) then %> UserParameter=FromDual.MySQL.check,/usr/local/mysql_performance_monitor/FromDualMySQLagent.pl /usr/local/mysql_performance_monitor/etc/FromDualMySQLagent.conf <% end %> I defined the variable $mysqlsrv = "true" in node.pp. However, it seems the file is really never updated based on the condition. Any suggestions how to troubleshoot this issue? I feel a bit lost. -- 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/-/DmKKquuBOGkJ. 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, That is a string you are checking in the has_variable not a Boolean. So if you put ''true'' or ''false'' they both pull the var into existence. So as far as I recall, you got two options. Try declaring the var like so: $mysqlsrv = true Or you run the template like this:> <% if has_variable?( "mysqlsrv" ) then %><% if mysqlsrv == ''true'' then ... Cheers, Den On 02/03/2012, at 14:16, "Will S. G." <will@arw.in> wrote:> I have a template for zabbix_agentd.conf.erb that has the following line in it: > > <% if has_variable?( "mysqlsrv" ) then %> > UserParameter=FromDual.MySQL.check,/usr/local/mysql_performance_monitor/FromDualMySQLagent.pl /usr/local/mysql_performance_monitor/etc/FromDualMySQLagent.conf <% end %> > > I defined the variable $mysqlsrv = "true" in node.pp. However, it seems the file is really never updated based on the condition. > > Any suggestions how to troubleshoot this issue? I feel a bit lost. > -- > 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/-/DmKKquuBOGkJ. > 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.-- 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.
Thanks Den, What if I were to define a string instead of boolean? $mysqlsrv = ''mysqlsrv'' That means <% if has_variable?( "mysqlsrv" ) then %> should work, no? Even with your recommended solution, I end up with Could not find value for ''mysqlsrv,'' which is what I ran into while troubleshooting/experimenting with the variable, etc. Any other suggestions? -- 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/-/lIgz5GOgewYJ. 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.
Right, didn''t properly read your original post. You''re declaring this in node.pp. Where are you declaring the template call? Can you paste how you are doing this so we can see? http://docs.puppetlabs.com/learning/templates.html#some-simple-erb In that link puppetlabs talk about the scopes of variables when using templates. You might need to use scope.lookupvar in your case. Den On 02/03/2012, at 15:18, "Will S. G." <will@arw.in> wrote:> Thanks Den, > > What if I were to define a string instead of boolean? > > $mysqlsrv = ''mysqlsrv'' > > That means <% if has_variable?( "mysqlsrv" ) then %> should work, no? > > Even with your recommended solution, I end up with Could not find value for ''mysqlsrv,'' which is what I ran into while troubleshooting/experimenting with the variable, etc. > > Any other suggestions? > -- > 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/-/lIgz5GOgewYJ. > 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.-- 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 Bukowinski
2012-Mar-02 05:41 UTC
Re: [Puppet Users] Puppet condition based on variable.
In this case, you should check for the variable''s value, as well:
<% if has_variable?("mysqlsrv") and mysqlsrv ==
''mysqlsrv'' %>
But it sounds like you might be having a variable scoping issue. Where in your
nodes.pp file do you have $mysqlsrv defined?
-- Peter (from phone)
On Mar 1, 2012, at 11:18 PM, "Will S. G." <will@arw.in> wrote:
> Thanks Den,
>
> What if I were to define a string instead of boolean?
>
> $mysqlsrv = ''mysqlsrv''
>
> That means <% if has_variable?( "mysqlsrv" ) then %> should
work, no?
>
> Even with your recommended solution, I end up with Could not find value for
''mysqlsrv,'' which is what I ran into while
troubleshooting/experimenting with the variable, etc.
>
> Any other suggestions?
> --
> 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/-/lIgz5GOgewYJ.
> 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.
--
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.
I''m not being descriptive, I know. I''ll clarify as
pseudo-code; I''m
essentially attempting to declare a variable in node.pp as such:
node ''util-mysql0'' inherits default {
$mysqlsr = [define value]
....
}
So:
- Define variable
- Create the condition in the template
- If var condition is met. Add line to the file for that node.
- Rinse, lather and repeat.
As you can see, by defining the variable, I''m attempting to predefine
the
condition. I would like to re-write the template, rather include the extra
line (the aforementioned) when the variable is defined for the node. If my
approach is incorrect, I suppose I would ask that you let me know. If not
then, please let me know what I might be missing.
--
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/-/kT1GluO0QTkJ.
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.
Here is an example using inline templates. Should describe how you can do it.
class myclass {
}
class myclass::config {
$myvar = "this is class text"
}
class myclass::template {
include myclass::config
$myvar = $myclass::config::myvar
$mytemplate = inline_template("
Here is some text.
Myvar should go here:
<% if has_variable?(''myvar'') -%>
<% if myvar =~ /text/ -%>
<%= myvar %>
this is your node var:
<%= scope.lookupvar(''nodevar'') -%>
<% else -%>
Don''t put text in.
<% end -%>
<% end -%>
")
notify {$mytemplate: }
}
node default {
$nodevar = ''this is node text''
include myclass::template
}
notice: /Stage[main]/Myclass::Template/Notify[
Here is some text.
Myvar should go here:
this is class text
this is your node var:
this is node text]/message: current_value absent, should be
Here is some text.
Myvar should go here:
this is class text
this is your node var:
this is node text (noop)
notice: Class[Myclass::Template]: Would have triggered
''refresh'' from 1 events
notice: Stage[main]: Would have triggered ''refresh'' from 1
events
notice: Finished catalog run in 0.07 seconds
In version 2.7.10 (which I''m using) I get a deprecation warning while
trying to access the node variable - I don''t declare variables that
way so I don''t know off hand how to fix it (tried several ways
quickly).
That should give you an idea anyway.
Den
On Fri, Mar 2, 2012 at 4:54 PM, Will S. G. <will@arw.in>
wrote:> I''m not being descriptive, I know. I''ll clarify as
pseudo-code; I''m
> essentially attempting to declare a variable in node.pp as such:
>
> node ''util-mysql0'' inherits default {
> $mysqlsr = [define value]
> ....
> }
>
> So:
>
> - Define variable
> - Create the condition in the template
> - If var condition is met. Add line to the file for that node.
> - Rinse, lather and repeat.
>
> As you can see, by defining the variable, I''m attempting to
predefine the
> condition. I would like to re-write the template, rather include the extra
> line (the aforementioned) when the variable is defined for the node. If my
> approach is incorrect, I suppose I would ask that you let me know. If not
> then, please let me know what I might be missing.
>
> --
> 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/-/kT1GluO0QTkJ.
>
> 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.
--
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.