Foreman API Example Find all hosts by given OS?

Foreman API Example Find all hosts by given OS? I need to query Foreman
for only hosts that have a given OS, for example 'CentOS' in the OS
parameter. I also need to find all hosts that are in a specific state. So
one query is all CentOS OS based hosts, and then all hosts that are a build
pending complete for example. Any help greatly appreciated! I am not all
familiar with JSON, but figure both queries would really use a GET or
customized URL syntax? I could not seem to find any examples beyond very
generic stuff, like list all hosts type of thing.

This gets all hosts, ok… but how do I narrow it to a specific OS type?
host state?

curl --user admin:changeme -H "Content-Type:application/json" -H
"Accept:application/json" -k https://foreman/api/v2/hosts

> Foreman API Example Find all hosts by given OS? I need to query Foreman
> for only hosts that have a given OS, for example 'CentOS' in the OS
> parameter. I also need to find all hosts that are in a specific state. So
> one query is all CentOS OS based hosts, and then all hosts that are a build
> pending complete for example. Any help greatly appreciated! I am not all
> familiar with JSON, but figure both queries would really use a GET or
> customized URL syntax? I could not seem to find any examples beyond very
> generic stuff, like list all hosts type of thing.
>
> This gets all hosts, ok… but how do I narrow it to a specific OS type?
> host state?
>
> curl --user admin:changeme -H "Content-Type:application/json" -H
> "Accept:application/json" -k https://foreman/api/v2/hosts
>

you should experiment with the search syntax on the UI (using the auto
completer). what you asked for could be done easily:

Add the following to your curl line:
-X GET -d '{"search":"build = true and os = Fedora"}'

or simply use hammer, our official foreman cli :slight_smile:

Ohad

··· On Mon, Dec 29, 2014 at 8:28 PM, Schorschi Decker wrote:


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/d/optout.

I was using…

curl --user admin:changeme -H "Content-Type:application/json" -H

"Accept:application/json" -k https://server/api/v2/hosts?search='CentOS
<https://foreman.dachshund-digital.org/api/v2/hosts?search='ESXi>'

But your example, the syntax seems more flexible… thanks for the example.