Unable to inherit values from a hostgroup

**Problem:Unable to inherit value from a hostgroup

**Expected outcome:*Expect to auto-populate inherited values on a host via hostgroup *

**Foreman and Proxy versions:3.2.1

**Foreman and Proxy plugin versions:3.2.1

**Distribution and version:3.2.1

Other relevant data:

Inheriting values from a hostgroup works just fine on our 3.2.1 installation. Could you elaborate what exactly you are trying to do and where it fails?

Our Setup is as below

parten hostgroup: collection

child hostgroup: collection_dev

A new server register with Katello (subscription-manager) and it gets hostgroup from curl api call.

The new servers does not get values of puppet ca, puppet proxy fields and environment names which we expect to be auto-filled from collection_dev group (we have tried with inherited way of setting and hard coded values but nothing works). We have to set them manually.

So, your workflow is (if I understand correctly):
You deploy your systems without Foreman, then register them via subscription-manager and finally set the hostgroup via API call. If that is correct, I assume the problem is that inheritance from hostgroups is (to my knowledge) not reapplied when the hostgroup is changed, at least not for smart-proxies.
This is in fact a limitation of switching hostgroups after host creation, and you have limited options to work around that. Since you are already using an API call to set the hostgroup, I would suggest to add additional API calls for changing the smart-proxies.
There is also GitHub - theforeman/foreman_default_hostgroup: A plugin to set the default hostgroup when hosts are created. which could help with your problem, but I think it only works on Puppetfacts and so won’t help in setting the correct hostgroup if the hosts are registered through subscription-manager.

There are probably reasons or opinionated assumptions for why smart-proxies are not re-inherited when a host is moved to another hostgroup, but that would need to be answered by a dev who has knowledge of that design decision from back when it was implemented like this.

I agree with what you are saying. We are using API calls to set the correct hostgroup, puppetserver, and environment names.

We require multiple hostgroups for different hosts and katello subscription-manager script is useful for adding new hosts. This does not require adding many interfaces and operating system related information manually and works well for our needs.

It would be good to know if there are options to create a host using API directly without requiring too much information (a similar approach like katello registration i.e. org name, server URL and activation key since hosts are not getting created via foreman).

According to API docs on my 3.2.1 Foreman, the only required field to create a host are name, location and organization. Everything else seems to be optional. Check /apidoc/v2/hosts/create.html on your Foreman server for more information.
This way you could create the host with all the values you require and won’t have to hassle with anything else.

curl --request POST --insecure --user xxxx:xxxxx -H “Content-Type:application/json” -H “Accept:application/json” -d ‘{“host”:{“name”:“test-api.example.com”,“organization_name”: “Default Organization”,“location_name”: “Default Location” }}’ https://xx.xx.xx.xx/api/hosts
{
“error”: {“id”:null,“errors”:{“interfaces.mac”:[“can’t be blank”],“operatingsystem_id”:[“can’t be blank”],“architecture_id”:[“can’t be blank”]},“full_messages”:[“Mac can’t be blank”,“Operatingsystem can’t be blank”,“Architecture can’t be blank”]}
}
It asks for other info as well.

OK, I see it now in the docs, too.
While these values are hypothetically optional, Operating System and Architecture (and probably some more values) need to be set if they are not inherited from a hostgroup. MAC is optional only for hosts that Foreman knows are VMs on a connected compute ressource.

We are not changing the host group. we run the script provided by foreman with the correct hostgroup. That script runs subscription manager first and then the api:

subscription-manager register --force \
  --org='Default_Organization' \
  --activationkey='AK_something' || true

register_katello_host | bash

So what is the official / correct way to register a host to the correct host group and it inherits the values for the group without more actions required?

To be honest, I don’t think I can help you anymore with this.
I don’t have any experience with the global_registration workflow and looking at the templates, I don’t even understand how it works to the point you got.

That works for me. Is it possible, the host has been registered before?

we always remove the host before re-registering.
Is there maybe a log we can check?

Somehow, it’s not really clear how you create the new host.

Do you use the “Create Host” interface? Do you first create the host in foreman and that register the client to it?

Do you use “Register Host”? Do you use the bash script retrieved via curl without any modification? What you have posted before doesn’t exactly look like the script generated on my foreman server. For me, the curl call inside register_katello_host sets the hostgroup of the host, even if it was already registered…

Does the host group have an activation key set?

We don’t use the “create host” interface. We use subscription-manager with an activation key along with organization and location name and curl to POST /api/register to register with host group id.

We use “Register Host” and we use a set of commands from the script and also tried not modifying the script which only successfully change host group but it does not inherit the environment, puppet ca and puppet proxy values set on a host group.

We don’t have an activation key set on host group since we use with subscription-manager command.