Host Groups are NOT working correctly

Problem:
Host groups do not work as expected.
Let’s assume that I have 2 organizations:

  1. OrganizationA
  2. OrganizationB

Plus 2 Locations:

  1. France
  2. USA

Now I would like to create a host group called “WORKSTATIONS” which will be applied to 2 separate organizations and locations.
I am NOT allowed to do that. I would like to have “Workstations” host group added to each location, e.g.:

OrganizationA\USA\Workstations
OrganizationB\France\Workstations

And it doesn’t work - ‘name has already been taken’ error is generated.
Even though Location and Organization do NOT matter here as I can’t even add host group under the same name to 2 separate organizations. For some reason “Host Groups” are global which totally doesn’t make sense because when you view the host groups in the Configure/Host Groups tab, they are NOT global, e.g.
When I select OrganizationA & France I can see host groups which were added ONLY to that Org & Location.
Likewise, when I select OrganizationB & USA I can see host groups which were added ONLY to that Org & Location… or rather I can see empty list because I couldn’t add “Workstation” host group.
:melting_face:

It is the same with the Foreman API. Proof:

No of host groups added to the location ‘26’

/api/locations/26/hostgroups
{
    "total": 0,
    "subtotal": 0,
    "page": 1,
    "per_page": 20,
    "search": null,
    "sort": {
        "by": null,
        "order": null
    },
    "results": []
}

Location 25 has many host groups added:

/api/locations/25/hostgroups
{
    "total": 1688,
    "subtotal": 1688,
    "page": 1,
    "per_page": 20,
    "search": null,
    "sort": {
        "by": null,
        "order":
...

Trying to add a new host group using POST call:

 {
    "location_id": 26,
    "hostgroup": {
        "name": "Workstations"
    },
    "organization_id": 5
}

Result:

{
    "error": {
        "id": null,
        "errors": {
            "name": [
                "has already been taken"
            ]
        },
        "full_messages": [
            "Name has already been taken"
        ]
    }
}

I even tried with:

 {    
    "hostgroup": {
        "name": "Workstations",
        "location_ids": [26],
        "organization_ids": [5]
    }    
}

and result is the same.

Expected outcome:
I would like to create host group under the same name for different organizations and locations.

Foreman and Proxy versions:
3.8

Distribution and version:
Ubuntu 20.04

Most of the resources in vanilla Foreman work like this. They are created (and their uniqueness is enforced) on the global level and you can then add them to organizations and locations. This is unlikely to change in the foreseeable future.

Would setting the context to any organization, creating the hostgroup and assigning the hostgroup to both organizations do roughly the same?

Most of the resources in vanilla Foreman work like this. They are created (and their uniqueness is enforced) on the global level and you can then add them to organizations and locations. This is unlikely to change in the foreseeable future.

If it’s the case, if hostgroup are in fact global why when I list host groups I get the results which I mentioned in the previous post, so to better illustrate this problem:

If they are global I should see hostgroups even I switch to OrganizationA?
But it’s not the case.

Moreover, why when I create a host and select an OrganizationB & LocationY I can see only 1 host group which was added specifically to that Org & location:


But If I change Location to some other to which I didn’t add any host groups I get no results:

Same thing when you try to change a host group for an existing host…
There’s no cosnequence here. :exploding_head:

Would setting the context to any organization, creating the hostgroup and assigning the hostgroup to both organizations do roughly the same?
Example which I provided - WORKSTATIONS, is not what I am trying to achieve here. That was only an example to illustrate the problem.
Let’s assume my host group should be called 1234, but this host group in LocationX and LocationY even they have the same name, mean something completely different, they are unique. I don’t know whether it makes sense. But for me it is.

That depends. You should only see the hostgroups in the organizations they are assigned to. Is the workstations hostgroup assigned to OrganizationA?

If there are no hostgroups assigned to that location, why would they be listed?

If there are no hostgroups assigned to that location, why would they be listed?

What’s the point of assigning group to a Location or Organization if host groups are global?
It shouldn’t really matter.

They are global as in “their names have to be globally unique”. By assigning them to locations and organizations, you control where they are visible and therefore where they can be used.

Could you do what you want with inheritance?

Workstation [Parent Group]

  • Org A/Location A/Workstation A
  • Org B/Location B/Workstation B

You can apply settings at the parent level and they’ll be inherited. Maybe I’m missing some context though.