ok.. I am going crazy,,

60 views
Skip to first unread message

ivan roseland

unread,
May 14, 2015, 6:41:54 PM5/14/15
to puppet...@googlegroups.com
I have some hiera:

"sys_gemfirexd::gemfire_users": {
     "gemfirexd.user.test": { "password": "XXXXXXXXXX" }
    },


I have some puppet :

  $gemfire_users=hiera_hash('sys_gemfirexd::gemfire_users', undef )
  if $gemfire_users == undef {
    $gemfire_users_test = "undef"
    }
    else {
      $gemfire_users_test = "ok"
      }


ok, I am not particularly proud of that bit, but.. I only occasionally need to have this last bit happen.. So, if its not defined in hiera it should not actually happen in the template..

I have some template:

<% if gemfire_users_test != "undef" -%>
<% gemfire_users.each_pair do |key, val| -%>
<%= key -%>=<%= gemfire_users['password']%>
<% end -%>
<% end -%>



Which is producing:
gemfirexd.user.test=


So fare so good, I at least have it dropping the key, now I would really like to get the value of password to drop..

I am suddenly having a difficult time wrapping my head around the needed ruby to make that part happen..



ivan roseland

unread,
May 14, 2015, 7:04:47 PM5/14/15
to puppet...@googlegroups.com


 yes, crazy,,

"sys_gemfirexd::gemfire_users": [
         { "name": "XXXXXXXX",
           "password": "password_123"
         }
    ],

<% if gemfire_users_test != "undef" -%>
<% gemfire_users.each do |gemfire_users| -%>
<%= gemfire_users['name'] -%>=<%= gemfire_users['password']%>
<% end -%>
<% end -%>


and now.. 

gemfirexd.user.test=XXXXXXXX

much better.. 

Stephen Marlow

unread,
May 14, 2015, 11:31:21 PM5/14/15
to puppet...@googlegroups.com
For what it's worth, variables with a value of undef will be nil in templates. You can use the .nil? method to check them, so you don't need to make a test variable there. Additionally, you should refer to variables in templates with an @, such as @gemfire_users instead of gemfire_users.

Here's a link to the doc, if you're interested: https://docs.puppetlabs.com/guides/templating.html#referencing-variables .

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/8798a62d-e1d1-4dfe-a527-9b49f8bf8f6a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ivan Roseland Roseland

unread,
May 14, 2015, 11:59:25 PM5/14/15
to puppet...@googlegroups.com
Ahhh excellent, I can make this even better then..

From: Stephen Marlow
Sent: ‎5/‎14/‎2015 8:31 PM
To: puppet...@googlegroups.com
Subject: Re: [Puppet Users] Re: ok.. I am going crazy,,

You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/4-4C26gghy4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CALGSqjJri75JmnrH_Zmscz7AMvUXP7ro_4s14mj%3DNO3d4MfzRA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages