Puppet Foreman lookup parse issues

Further troubleshooting proved this to be simple ignorance on the data
structure coming from foreman. The correct syntax is below, where the
static 'host' hash needed to be part of the variable. It might be helpful
to add to the blog post or create more formal documentation with examples
for the ruby-challenged folks :slight_smile:

<% i=0 -%>
<% nodearray.each do |vhash| %>
server.<%= i %>=<%= vhash['host']['name'] %>:2388:3888
<% i=i+1 -%>
<% end -%>

路路路 On Wednesday, March 13, 2013 9:41:44 AM UTC-5, Andrew Cooper wrote: > > Hello, > > I have started a project to move our current puppet / cobbler setup to > foreman. I am very impressed with the project and I hope to see good > things in the future! > > My issue is happening with the foreman lookup function described in this > blog post: > http://blog.theforeman.org/2012/01/getting-foreman-search-results-into.html > > I am using a "hosts" lookup with a simple parameter search. It appears > that the lookup is returning the correct json, but when I attempt to > interact with the returned array in a ruby erb, it does not appear to have > parsed correctly. We are using puppet 2.7.1 for client and server, I am > not sure if I am running into a bug with the other version of puppet, vs > the versions this was tested with? Below is all of the output I am seeing. > Basically, it seems like the "host" hash is getting stripped of its > structure and being converted into a string with all the data smashed > together. I am unable to access the keys within the hash correctly. Any > help would be appreciated! > > Manifest call: > $nodearray = foreman("hosts", 'params.zoo_instance = 1') > > > Pretty Printed JSON from same lookup using curl (to prove that the call is > working): > > [ > { > "host": { > "operatingsystem_id": 3, > "name": "zk1.cloud.dev", > "hostgroup_id": 3, > "id": 512 > } > } > ] > > > > ERB snippet showing just the hash: > > #now add the ip addresses > <% i=0 -%> > <% nodearray.each do |vhash| %> > server.<%= i %>=<%= vhash %>:2388:3888 > <% i=i+1 -%> > <% end -%> > > output: > server.0=*hostnamezk1.cloud.devid512hostgroup_id3operatingsystem_id3* > :2388:3888 > > > intended ERB snippet attempting to template hostname (vhash['name'] is not > defined): > > #now add the ip addresses > <% i=0 -%> > <% nodearray.each do |vhash| %> > server.<%= i %>=<%= vhash['name'] %>:2388:3888 > <% i=i+1 -%> > <% end -%> > > output: > server.0=:2388:3888 >