erb logic with a hiera value

321 views
Skip to first unread message

Wolf Noble

unread,
May 19, 2012, 12:57:14 PM5/19/12
to puppet...@googlegroups.com

so I've set a hiera key, and trying to display some different data in motd depending on if the value of said key is true or false… it gets set accordingly.. but my motd template doesn't seem to be properly reacting when the value of it changes..

it's as if the variable never matches "true"
not sure what I'm doing wrong here…. I SUSPECT 'true' isn't being perceived as such somehow…

Can anyone spot what I'm missing?



bash-3.2$ cat /etc/puppetlabs/puppet/modules/core/manifests/values.pp
#
# core::values
# a class for namespaceing variables not specifically linked to any other module.
class core::values {
$foostatus = hiera('core_values_foo')
}



bash-3.2$ cat hieradata/(extraneous tree pruned)/Prod/common.yaml
core_values_foo: - true



bash-3.2$ cat hieradata//common.yaml
core_values_foo: - false


bash-3.2$ cat core/motd/templates/motd.erb
<% foostatus = scope.lookupvar('core::values::foostatus') -%>
## Configuration Notice ##----------------------------------
The configuration of <%= hostname -%> is managed by Puppet.
### QuickStats from last puppetrun
RAM: <%= memorysize -%> ::
<%= lsbdistdescription %>
Kernel: <%= kernelrelease %>
Internal IP: <%= ipaddress %>
###########################################################
<% if foostatus == "true" -%>
| foo is true |
`****************************************************'
<% else -%>
| foo is not true |
`****************************************************'
<% end-%>
<%= foostatus %>
bash-3.2$



[root@bookworm ~]# cat /etc/motd
## Configuration Notice ##----------------------------------
The configuration of bookworm is managed by Puppet.
### QuickStats from last puppetrun
RAM: 512.18 MB ::
CentOS release 5.8 (Final)
Kernel: 2.6.18-308.4.1.el5xen
Internal IP: 123.123.123.123
###########################################################
| foo is not true |
`****************************************************'
true



if I remove the entry which is setting it to true in hieradata/(pruned)Prod/common.yaml:

[root@bookworm ~]# cat /etc/motd
## Configuration Notice ##----------------------------------
The configuration of bookworm is managed by Puppet.
### QuickStats from last puppetrun
RAM: 512.18 MB ::
CentOS release 5.8 (Final)
Kernel: 2.6.18-308.4.1.el5xen
Internal IP: 123.123.123.123
###########################################################
| foo is not true |
`****************************************************'
false





________________________________

This message may contain confidential or privileged information. If you are not the intended recipient, please advise us immediately and delete this message. See http://www.datapipe.com/legal/email_disclaimer/ for further information on confidentiality and the risks of non-secure electronic communication. If you cannot access these links, please notify us by reply message and we will send the contents to you.

Gary Larizza

unread,
May 19, 2012, 12:59:09 PM5/19/12
to puppet...@googlegroups.com
This is the problem - you're trying to compare a boolean value of true to a string value of 'true'.  Just do something like:

<% if foostatus -%>

That should work for you :)

 

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.




--

Gary Larizza
Professional Services Engineer
Puppet Labs

Wolf Noble

unread,
May 19, 2012, 1:11:49 PM5/19/12
to <puppet-users@googlegroups.com>
Thanks Gary,

I knew it was something simple.

Appreciate the help


<% if foostatus == "true" -%>

This is the problem - you're trying to compare a boolean value of true to a string value of 'true'. Just do something like:

<% if foostatus -%>

That should work for you :)

Reply all
Reply to author
Forward
0 new messages