Using Foreman API within Puppet module

I came across


recently, and wanted to do something similar in my environment to
automatically fill in a hostlist. I see that
https://github.com/theforeman/puppet-foreman/blob/master/lib/puppet/parser/functions/foreman.rb
has changed a bit since the writing of the blog post, so I updated my
syntax and used:

class blah::params {
$foremanArgs = { item => 'hosts',
search => 'hostgroup=Grid',
foreman_url => 'https://foreman',
foreman_user => 'apiuser',
foreman_pass => 'password'
}
$nodes = foreman($foremanArgs)
}

I've tested this query elsewhere using Ruby
(see see https://gist.github.com/patcable/913f29128108d0e716c6), and it
returns the data I would expect.

I have a template:
<% nodes.each do |node| -%>
<% node.each do |key,value| -%>
<%= value['name'] %>
<% end -%>
<% end -%>

Yet, the file it's supposed to create shows up empty.

Am I missing something? Also, how should I specify a greater host return
limit, since the puppet module doesnt seem to have a good way to specify
per_page?

Thanks for any thoughts,

  • Patrick

> I came across
> http://blog.theforeman.org/2012/01/getting-foreman-search-results-into.htmlrecently, and wanted to do something similar in my environment to
> automatically fill in a hostlist. I see that
> https://github.com/theforeman/puppet-foreman/blob/master/lib/puppet/parser/functions/foreman.rbhas changed a bit since the writing of the blog post, so I updated my
> syntax and used:
>
> class blah::params {
> $foremanArgs = { item => 'hosts',
> search => 'hostgroup=Grid',
> foreman_url => 'https://foreman',
> foreman_user => 'apiuser',
> foreman_pass => 'password'
> }
> $nodes = foreman($foremanArgs)
> }
>
> I've tested this query elsewhere using Ruby (see see
> https://gist.github.com/patcable/913f29128108d0e716c6), and it returns
> the data I would expect.
>
> I have a template:
> <% nodes.each do |node| -%>
> <% node.each do |key,value| -%>
> <%= value['name'] %>
> <% end -%>
> <% end -%>
>

> Yet, the file it's supposed to create shows up empty.
>

This looks right… Can you add some puppet debug statements ?

>
> Am I missing something? Also, how should I specify a greater host return
> limit, since the puppet module doesnt seem to have a good way to specify
> per_page?
>

This seems a limitation of the current function, it should be extended to
include additional parameters (or accept a parameters hash) like per_page,
order, page etc…

Patches are welcomed :wink:

Thanks!
Ohad

··· On Tue, Oct 22, 2013 at 2:46 AM, Patrick Cable wrote:

Thanks for any thoughts,

  • Patrick


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/groups/opt_out.

I'll respond for the sake of anyone who may come across this in a search :slight_smile:

>
>
>> I have a template:
>> <% nodes.each do |node| -%>
>> <% node.each do |key,value| -%>
>> <%= value['name'] %>
>> <% end -%>
>> <% end -%>
>>
>
>> Yet, the file it's supposed to create shows up empty.
>>
>
> This looks right… Can you add some puppet debug statements ?
>

I did some more debug.

If I call the parameter that directly calls foreman() it works.

<% scope['torque::params::nodes'].each do |node| -%>
<% node.each do |key,value| -%>
<%= value['name'] %>
<% end -%>
<% end -%>

If I try scope['torque::nodes'] no dice. Same for @nodes. Admittedly I'm
not very familiar with adding in more debug options, but am happy to do so
with some guidance.

> Am I missing something? Also, how should I specify a greater host return
>> limit, since the puppet module doesnt seem to have a good way to specify
>> per_page?
>>
>
> This seems a limitation of the current function, it should be extended to
> include additional parameters (or accept a parameters hash) like per_page,
> order, page etc…
>

Sure! See: https://github.com/theforeman/puppet-foreman/pull/120

  • Patrick
··· On Tuesday, October 22, 2013 1:53:43 AM UTC-4, ohad wrote: > On Tue, Oct 22, 2013 at 2:46 AM, Patrick Cable <p...@pcable.net > > wrote: