Getting list of hosts for a hostgroup, including subgroups via the API

Hi
I am trying to get a list of hosts that belong to a host group. However the
hostgroup itself does not directly contain any hosts, the subgroups does
however.

Using the API I can get a list of hosts per hostgroup
using https://localhost/api/hostgroups/<hostgroup number>/hosts
I can get a description of the hostgroup using /api/hostgroups/<hostgroup
>

What I can't seem to get is a list of subgroups using the API and thus no
easy way of getting all the hosts in a parent group.

Other than building my own hierarchy from api/hostgroups is there a way of
getting all hosts including hosts in subgroups for a particular hostgroup?

Regards

Hi,
You can get a list of all hosts in hostgroup or subgroups using searching
(both in the UI and API).
For example, of all of hostgroup named hg1 and subgroups you can use
"http://localhost:3000/api/v2/hosts?search=hostgroup_title~hg1*"
For only the subgroups:
"http://localhost:3000/api/v2/hosts?search=hostgroup_title~hg1/*"

The same search sting can also be used on the UI

··· On Mon, Jul 10, 2017 at 10:56 AM, Gerhardus Geldenhuis < gerhardus.geldenhuis@gmail.com> wrote:

Hi
I am trying to get a list of hosts that belong to a host group. However
the hostgroup itself does not directly contain any hosts, the subgroups
does however.

Using the API I can get a list of hosts per hostgroup using
https://localhost/api/hostgroups//hosts
I can get a description of the hostgroup using /api/hostgroups/<hostgroup

What I can’t seem to get is a list of subgroups using the API and thus no
easy way of getting all the hosts in a parent group.

Other than building my own hierarchy from api/hostgroups is there a way of
getting all hosts including hosts in subgroups for a particular hostgroup?

Regards


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 https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.


Have a nice day,
Tomer Brisker
Red Hat Engineering

Thanks! That is really helpfull. Should I have found that in the docs? I am a firm believer of rtfm but googling has made me a worse reader.

Regards