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.
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
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 1
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 v
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 troubleshooti
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?
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