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.
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.
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.
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.
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.
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”.
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.
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.
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.
Hello! I know this is a few years old, but I am having similar issues with removing a host from puppet master. I load up the foreman-rake console environment, and run the command: "host = Host.find(id) but get this message: ActiveRecord::RecordNotFound (Couldn’t find Host::Managed with ‘id’=276 [WHERE “hosts”.“type” = $1])
I also tried: Host.where(id: [276]).destroy_all and received an empty array.