Can not change hostgroup_id via REST API

Problem:
and again a problem :frowning:

I would like to change the host_group externally (from the client) via REST API via:
curl -k -u $USERNAME:$PASSWORD -X PUT -H "Content-Type:application/json" -H "Accept:application/json" -d "{\"host\":{\"hostgroup_id\":\"4\"}}" $KATURIBASE/hosts/$HOSTNAME
Unfortunately, instead of making the change here, Foreman tries to directly create a new! host:
"error": {"id":14, "errors":{"base":["Failed to create a compute ESX_Test Environment (VMware) instance sfravm-fi-test1-46: DuplicateName: The name 'sfravm-fi-test1-46' already exists. \n "]}, "full_messages":["Failed to create a compute ESX_Test Environment (VMware) instance sfravm-fi-test1-46: DuplicateName: The name 'sfravm-fi-test1-46' already exists.\n "]}
If I want to change e.g. the comment field with the above command, it works without problems.
Is this a BUG or how else can I do it via REST?

Best regards

Expected outcome:
host_group is changed
Foreman and Proxy versions:
3.5.1

addition: if I try to do this via hammer, there is the same error:

hammer -u XXX -p YYY host update --name  sfravm-fi-test1-46 --hostgroup-id 6
Could not update the host:
  Failed to create a compute ESX_Testumgebung (VMware) instance sfravm-fi-test1-46: DuplicateName: The name 'sfravm-fi-test1-46' already exists.

or with id

hammer -u XXX -p YYY host update --id=14 --hostgroup-id 6
Could not update the host:
  Failed to create a compute ESX_Testumgebung (VMware) instance sfravm-fi-test1-46: DuplicateName: The name 'sfravm-fi-test1-46' already exists.

strange behaviour in my opinion

and one more note: all hosts are created externally. Foreman / Katello should only be used as patch / basic config management (via ansible).
Via the UI it works manually but I want to do this automatically after registering a new host.

By the way: please can someone with admin rights change the headline typo from REAST to REST :wink:

Hello,

I do not know if it is of any help, I change the host’s hostgroup via hammer like this and I think that content view and lifecycle parameters are obligatory:

hammer host update --organization $ORGANISATION --name $HOST_NAME --content-view $CV --lifecycle-environment $LIFECYCLE --hostgroup-title $NEW_HOSTGROUP

(Fixed the typo in the title)

Could it be that the HG you’re trying to move the host to has a compute resource assigned and Foreman (for some reason, smells like a bug to me) tries to deploy a new machine using that compute resource?

@JendaVodka
thank for your advice, but same result :frowning: foreman tries to create a new host

@evgeni
yes this host group has a compute resource assigned and that could be the problem (successful test with new empty host group without any other settings). But the interesting thing is that when I do this via the UI (hosts page → select host → change group) it doesn’t cause any problems.
But since all the hosts are created via foreman in the ESX environment, I can’t change this (and it shouldn’t be a problem).

Greeting

Frank

Yeah, totally agree that this shouldn’t be a problem. Just trying to narrow down where this is coming from.

as I said, the test with the move to a hostgroup without “deploy on” (i.e. without compute resource) was successful, which means that your assumption is correct.