Validation failed: Name has already been taken, when registering a client

Problem:
Validation failed: Name has already been taken, when registering a client

Expected outcome:
Subscribed

Foreman and Proxy versions:
2.4.0
Foreman and Proxy plugin versions:
Foreman 2.4.0 and Katello 4.0.1

Distribution and version:
RHEL 7.9 (Maipo)

Other relevant data:

Unable to register few RHEL6 servers, below is what I am getting when I run subscription-manager register…

subscription-manager register --org=“Default_Organization” --activationkey=“Activation_key6”

Validation failed: Name has already been taken

Please help.

Thanks in advance,

Best regards,
Balaji Sankaran

Could it be that the host with the same hostname -f exists in your Foreman?

Hello Marek_Hulan,

No, the hostname of the servers which have issues, doesn’t exist in Foreman, have the issues since Katello 3.18, I deleted them to resolve the issues, but it did not work, then I thought it would resolve after upgrading to Katello 4.0.1 and upgraded, but the issues still there.

Best regards,
Balaji Sankaran

Are you really sure it doesn’t exist in foreman? Did you check with hammer?

# hammer host list

Hello gvde,

Yes, I also checked with hammer and it doesn’t exist. Any idea what it could be?

Best regards,
Balaji Sankaran

Make sure to search through all orgs/locs. The hostname must be unique for the entire Foreman DB, which can be unexpected. Best is to try to find it under admin in Any Org + Any Loc context.

Hello Marek_Hulan,

I searched through the organization(in this environment there is only one Organization in the location), I searched using admin account, still no luck. I have 3 hosts with same issues and they are RHEL 6.10.

Please help,

Best regards,
Balaji Sankaran

I’m sorry, I’m out of ideas. Perhaps looks at the database - hosts table and see if there’s this name already used. The validation error is pretty clear, for some reason it thinks there’s already host with such name.

Hello,

I deleted all the hosts in the organization, but still I am getting “Validation failed: Name has already been taken”, wondering why it complains when there are no hosts registered.

Please help.

Thanks & regards,
Balaji Sankaran.

Check the database for any hosts left in any organization and/or location. Run the following as root on the foreman server:

# sudo -u postgres psql foreman -c 'select id, name, organization_id, location_id from hosts;'

It lists all hosts in the foreman hosts database table…

1 Like

Hello gvde,

I ran the command as you recommended and I see the hosts with problems listed along with other hosts. Attached is the command output screen shot, I highlighted the hosts in yellow which have the error "Validation failed: Name has already been taken”.

Could you please help me remove them?

Best regards,
Balaji Sankaran

I guess that’s rather something for @Marek_Hulan or one of the other developers. There seem to be some hosts in the database which are “half deleted” I guess.

If you want to delete these hosts, perform the following:

foreman-rake console
Host.where(id: [233, 265, 274]).destroy_all
exit

Hi Marek_Hulan,

I tried to delete hosts using the foreman-rake console command, but it is not deleting the hosts.
Attached is the screen shot of the command output.

Please help.

Best regards,
Balaji Sankaran

For some reason, the search didn’t find any host with these ids (the result was [] which means empty array). Let’s try this first

foreman-rake console
host = Host.find(233)
host.destroy
exit

Recently I’ve seen people reporting having host records using the wrong type. That could explain it. Try also this

# sudo -u postgres psql foreman -c 'select id, name, type, organization_id, location_id from hosts;'

If you’ll see Host::Base in the resulting table, it explains everyting. In such case, this should work

foreman-rake console
Host::Base.where(id: [233, 265, 274]).destroy_all
exit

potentially it could fail with another error on deletion, that’s being discussed at Reports Processing Failure (AssociationTypeMismatch) - #12 by Marek_Hulan

Hi Marek_Hulan,

This worked and the issue was resolved by running “Host::Base.where(id: [233, 265, 274]).destroy_all” in foreman-rake console, there was no Host::Base in the output table for the command “sudo -u postgres psql foreman -c ‘select id, name, type, organization_id, location_id from hosts;’”, but the problematic hosts showing blank in the type column, whereas working hosts are showing “Host::Managed” in type column.

id | name | type | organization_id | location_id
------±--------------±----------±-------------------±---------------
233 | | | 2 | 1
274 | | | 2 | 1
265 | | | 2 | 1

Thank you so much for the help!!!

Best regards,
Balaji Sankaran

Thanks for the details, the empty type is really interesting. Please let us know if you see that happening again, I’d like to understand the real cause. Glad it helped.