Foreman Function

If I want to do multiple queries to get results
(there should be simpler) :

$hosts = foreman('hosts','facts.operatingsystem = Debian')
$subquery=inline_template("<%= hosts.map{|h|'host='+h['host']['name']}.join(' or ') %>")
$query="fact = hostname and ( ${subquery} )" 
$hostnames=foreman('fact_values',$query)

Then in my erb file :

<% hostnames.each do |hostname| %>
   <%= hostname[1]['hostname'] %>
<%end%>