HTTP error (422 - Unknown): Validation failed: Name has already been taken

Problem:
Trying to register a host (which was possibly registered before) fails with error.
I’ve tried cleaning up everything first:

sudo subscription-manager unregister
sudo subscription-manager remove --all
sudo subscription-manager clean

Then I try to register it:

# subscription-manager register --activationkey=some-key --org=some-org --force
HTTP error (422 - Unknown): Validation failed: Name has already been taken

The server by the name cannot be found in UI or with hammer:

# hammer host list --search server-1.domain.local
---|------|------------------|------------|----|-----|---------------|--------------|-----------------------|-------------
ID | NAME | OPERATING SYSTEM | HOST GROUP | IP | MAC | GLOBAL STATUS | CONTENT VIEW | LIFECYCLE ENVIRONMENT | TRACE STATUS
---|------|------------------|------------|----|-----|---------------|--------------|-----------------------|-------------

It is nowhere to be found in Foreman on any search.
I’ve tried overriding UUID just in case via rhsm facts, no luck.

Expected outcome:
To register normally.

Foreman and Proxy versions:
Foreman 2.3.2

Foreman and Proxy plugin versions:
Katello 3.18.1

Distribution and version:
CentOS 7

Other relevant data:

production.log:

2021-02-18T14:48:27 [I|app|2da915d1] Started POST "/rhsm/consumers?owner=some-org&activation_keys=some-key" for 127.0.0.1 at 2021-02-18 14:48:27 +0000
2021-02-18T14:48:27 [I|app|2da915d1] Processing by Katello::Api::Rhsm::CandlepinProxiesController#consumer_activate as JSON
2021-02-18T14:48:27 [I|app|2da915d1]   Parameters: {"name"=>"server-1", "contentTags"=>[], "serviceLevel"=>"", "usage"=>"", "role"=>"", "facts"=>"[FILTERED]", "addOns"=>[], "type"=>"system", "owner"=>"some-org", "activation_keys"=>"some-key"}
2021-02-18T14:48:28 [W|app|2da915d1] Not queueing Host::Managed: ["Name has already been taken"]
2021-02-18T14:48:28 [W|app|2da915d1] Not queueing Host::Managed: ["Name has already been taken"]
2021-02-18T14:48:28 [W|app|2da915d1] Not queueing Host::Managed: ["Name has already been taken"]
2021-02-18T14:48:28 [E|kat|2da915d1] <Class> ActiveRecord::RecordInvalid
2021-02-18T14:48:28 [E|kat|2da915d1] name: ["has already been taken"]
2021-02-18T14:48:28 [I|app|2da915d1] Completed 422 Unprocessable Entity in 220ms (Views: 0.1ms | ActiveRecord: 31.3ms | Allocations: 46822)

The error is very opaque in terms of what is actually raising the validation error. Is it the host name, is it the associated operating system…

I’m curious to see what’s in the database itself. If you run foreman-rake console in the terminal of the Foreman server and enter ::Host.find_by_name('server-1.domain.local') are any results returned?

Are you using puppet on any of your clients?

Thank you for looking into this. My entire infrastructure is managed by Chef, and all my servers are subscribed with subscription-manager via Chef cookbook I wrote using rhsm_register Chef resource. Puppet is only installed on smart proxies deployed around different datacenters during their deployment with foremam-installer.All servers are deployed from the same image.
These facts I’m excluding from DB if this is relevant.

lo,en*v*,usb*,vnet*,macvtap*,_vdsmdummy_,veth*,docker*,tap*,qbr*,qvb*,qvo*,qr-*,qg-*,vlinuxbr*,vovsbr*,proc_cpuinfo*,lscpu*,dmi.baseboard*,dmi.bios*,dmi.chasis*,dmi.memory*,dmi.processor*,cpu*

I have around 10 300 hosts, and this issue has appeared on 5 hosts, 4 in one DC, 1 in other DC.
Checking DB for those hostnames finds nothing, same as hammer and UI search.

# foreman-rake console
Loading production environment (Rails 6.0.3.4)
irb(main):001:0> ::Host.find_by_name('server-1.domain.local')
=> nil
irb(main):002:0> 

Ok! My suspicion is that this doesn’t have anything to do with the name of the hosts (the error would almost certainly be different) but rather the operating systems involved (as I’ve seen this happen a time or two before).

The next step is to take a look at Hosts -> Operating Systems in the UI and see if there are any obvious discrepancies such as anything seemingly duplicated. You may also want to clean up any which are unused (0 hosts associated to them).

It’s be helpful if you could share the output of hammer os list here, as well as subscription-manager facts output from the client host. Based on the facts of the client please also share specific details from the UI for the matching operating system such as the name, major and minor version.

Here is the OS list, same info in UI.

# hammer os list
---|-----------------------|--------------|-------
ID | TITLE                 | RELEASE NAME | FAMILY
---|-----------------------|--------------|-------
2  | CentOS 7              |              | Redhat
3  | CentOS 7.7.1908       |              | Redhat
1  | CentOS Linux 7.8.2003 |              | Redhat
4  | CentOS Linux 7.9.2009 |              | Redhat
---|-----------------------|--------------|-------

Here are the facts for the problematic machine:

cpu.core(s)_per_socket: 4
cpu.cpu(s): 4
cpu.cpu_socket(s): 1
cpu.thread(s)_per_core: 1
cpu.topology_source: kernel /sys cpu sibling lists
distribution.id: Core
distribution.name: CentOS Linux
distribution.version: 7
distribution.version.modifier: Unknown
dmi.baseboard.manufacturer: Microsoft Corporation
dmi.baseboard.product_name: Virtual Machine
dmi.baseboard.serial_number: 0886-3116-9651-2414-9543-9590-55
dmi.baseboard.version: Hyper-V UEFI Release v1.0
dmi.bios.bios_revision: 1.0
dmi.bios.relase_date: 11/26/2012
dmi.bios.rom_size: 64 KB
dmi.bios.runtime_size: Unknown
dmi.bios.vendor: Microsoft Corporation
dmi.bios.version: Hyper-V UEFI Release v1.0
dmi.chassis.asset_tag: 0886-3116-9561-2414-9543-9590-55
dmi.chassis.boot-up_state: Safe
dmi.chassis.lock: Not Present
dmi.chassis.manufacturer: Microsoft Corporation
dmi.chassis.power_supply_state: Safe
dmi.chassis.security_status: Unknown
dmi.chassis.serial_number: 0886-3116-9561-2414-9543-9590-55
dmi.chassis.thermal_state: Safe
dmi.chassis.type: Desktop
dmi.chassis.version: Hyper-V UEFI Release v1.0
dmi.memory.array_handle: 0x0009
dmi.memory.assettag: None
dmi.memory.bank_locator: None
dmi.memory.data_width: Unknown
dmi.memory.error_correction_type: None
dmi.memory.error_information_handle: No Error
dmi.memory.form_factor: Unknown
dmi.memory.location: System Board Or Motherboard
dmi.memory.locator: M0001
dmi.memory.manufacturer: Microsoft Corporation
dmi.memory.maximum_capacity: 2048 GB
dmi.memory.part_number: None
dmi.memory.serial_number: None
dmi.memory.size: 3968 MB
dmi.memory.speed:   (ns)
dmi.memory.total_width: Unknown
dmi.memory.type: Unknown
dmi.memory.use: System Memory
dmi.meta.cpu_socket_count: 4
dmi.processor.asset_tag: None
dmi.processor.family: Xeon
dmi.processor.part_number: None
dmi.processor.serial_number: None
dmi.processor.socket_designation: None
dmi.processor.status: Populated:Enabled
dmi.processor.type: Central Processor
dmi.processor.upgrade: None
dmi.processor.version: Intel(R) Xeon(R) Gold 6142 CPU @ 2.60GHz
dmi.processor.voltage: 0,9 V
dmi.system.family: Virtual Machine
dmi.system.manufacturer: Microsoft Corporation
dmi.system.product_name: Virtual Machine
dmi.system.serial_number: 0886-3116-9561-2414-9543-9590-55
dmi.system.sku_number: None
dmi.system.status: No errors detected
dmi.system.uuid: 0782e99d-ee3e-4fbe-88b4-d56f28602b2a
dmi.system.version: Hyper-V UEFI Release v1.0
dmi.system.wake-up_type: Power Switch
foreman_location: HR2
last_boot: 2020-10-03 21:04:00
lscpu.architecture: x86_64
lscpu.bogomips: 5187.80
lscpu.byte_order: Little Endian
lscpu.core(s)_per_socket: 4
lscpu.cpu(s): 4
lscpu.cpu_family: 6
lscpu.cpu_mhz: 2593.904
lscpu.cpu_op-mode(s): 32-bit, 64-bit
lscpu.flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt avx512cd avx512bw avx512vl xsaveopt xsavec spec_ctrl intel_stibp flush_l1d
lscpu.hypervisor_vendor: Microsoft
lscpu.l1d_cache: 32K
lscpu.l1i_cache: 32K
lscpu.l2_cache: 1024K
lscpu.l3_cache: 22528K
lscpu.model: 85
lscpu.model_name: Intel(R) Xeon(R) Gold 6142 CPU @ 2.60GHz
lscpu.numa_node(s): 1
lscpu.numa_node0_cpu(s): 0-3
lscpu.on-line_cpu(s)_list: 0-3
lscpu.socket(s): 1
lscpu.stepping: 4
lscpu.thread(s)_per_core: 1
lscpu.vendor_id: GenuineIntel
lscpu.virtualization_type: full
memory.memtotal: 10037016
memory.swaptotal: 1048572
net.interface.eth0.ipv4_address: 10.26.34.14
net.interface.eth0.ipv4_address_list: 10.26.34.14
net.interface.eth0.ipv4_broadcast: 10.26.34.255
net.interface.eth0.ipv4_broadcast_list: 10.26.34.255
net.interface.eth0.ipv4_netmask: 24
net.interface.eth0.ipv4_netmask_list: 24
net.interface.eth0.mac_address: DA:00:01:00:00:88
net.interface.lo.ipv4_address: 127.0.0.1
net.interface.lo.ipv4_address_list: 127.0.0.1
net.interface.lo.ipv4_broadcast: Unknown
net.interface.lo.ipv4_broadcast_list: Unknown
net.interface.lo.ipv4_netmask: 8
net.interface.lo.ipv4_netmask_list: 8
network.fqdn: server-1.domain.local
network.hostname: server-1
network.ipv4_address: 10.26.34.14
network.ipv6_address: ::1
proc_cpuinfo.common.address_sizes: 44 bits physical, 48 bits virtual
proc_cpuinfo.common.bogomips: 5187.80
proc_cpuinfo.common.cache_alignment: 64
proc_cpuinfo.common.cache_size: 22528 KB
proc_cpuinfo.common.clflush_size: 64
proc_cpuinfo.common.cpu_cores: 4
proc_cpuinfo.common.cpu_family: 6
proc_cpuinfo.common.cpu_mhz: 2593.904
proc_cpuinfo.common.cpuid_level: 21
proc_cpuinfo.common.flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt avx512cd avx512bw avx512vl xsaveopt xsavec spec_ctrl intel_stibp flush_l1d
proc_cpuinfo.common.fpu: yes
proc_cpuinfo.common.fpu_exception: yes
proc_cpuinfo.common.microcode: 0xffffffff
proc_cpuinfo.common.model: 85
proc_cpuinfo.common.model_name: Intel(R) Xeon(R) Gold 6142 CPU @ 2.60GHz
proc_cpuinfo.common.physical_id: 0
proc_cpuinfo.common.power_management: Unknown
proc_cpuinfo.common.siblings: 4
proc_cpuinfo.common.stepping: 4
proc_cpuinfo.common.vendor_id: GenuineIntel
proc_cpuinfo.common.wp: yes
proc_stat.btime: 1601759040
system.certificate_version: 3.2
system.default_locale: en_US.UTF-8
uname.machine: x86_64
uname.nodename: server-1
uname.release: 3.10.0-1127.19.1.el7.x86_64
uname.sysname: Linux
uname.version: #1 SMP Tue Aug 25 17:23:54 UTC 2020
virt.host_type: hyperv
virt.is_guest: True
virt.uuid: f03b8a46-bf3c-f34c-8260-7f25e8901385

I searched also for any IP and mac conflict through UI, if that exists, nothing found.

I am also having the same problem with adding three new hosts.

Exactly the same problem, in the command “hammer host list --search site-1.example” nothing is listed.

But when trying to register a new host with the hostname site-1.example, the error below is returned.

HTTP error (422 - Unknown): Validation failed: Name has already been taken

In my case, changing the hostname of the VM was not an option.

I was able to solve the problem with the steps below, after having done a full backup of the DB and a snapshot of the Foreman VM.

First step: I ran the commands below on the host I’m trying to register.
sudo subscription-manager unregister
sudo subscription-manager remove --all
sudo subscription-manager clean

Second step: I checked All Hosts and Content Hosts for ‘site-2.example’, and nothing was found, even changing for any organization.

Third step: I accessed the DB foreman in psql and searched for the host name with the select below, to identify the host id.
SELECT * FROM hosts WHERE name = ‘site-2.example’;
#id 126

Fourth step: with the host id in hand, I executed the deletes below.
DELETE FROM fact_values ​​WHERE host_id = 126;
DELETE FROM nics WHERE host_id = 126;
DELETE FROM host_facets_reported_data_facets WHERE host_id = 126;
DELETE FROM hosts WHERE id = 126;

That done, I managed to run the subscription-manager register again, this time successfully subscribing the host.

There were a total of three hosts with the same problem, I performed the same procedure for everyone and it was solved.

Thanks.

2 Likes

Marcelo, thank you very much for the solution!

2 Likes

Here is also an alternate solution, less proper that Marcelo’s.
You can override how server hostname will be written down in Foreman pgsql DB.
If your server full hostname is for example server-1.domain.local, you can override how its saved in Foreman DB with local facts.
Create a file /etc/rhsm/facts/override_hostname.facts with content:

{
  "network.fqdn":"server-1a.domain.local",
  "network.hostname":"server-1a",
  "uname.nodename":"server-1a"
}

So for all intensive purposes it can stay the same within your infra, but it will be slightly different in Foreman DB to avoid conflict there.

1 Like

I have tried to get into the postgresql server and even using the password it states, access is denied.
How did you get into postgres?
I’d love to solve this issue.

[quote=“matemikulic, post:10, topic:22462”]
/etc/rhsm/facts/override_hostname.facts
[/quote] /etc/rhsm/facts/override_hostname.facts

I got in and no hosts listed by that name…still trying to figure it out.
command: #subscription-manager register --org=“My_org_name” --activationkey=“activation-key”
output: HTTP error (422 - Unknown): Validation failed: Title has already been taken
Not sure what I am missing.
Any help is appreciated.

-> change to postgres user
su - postgres

-> on bash of postgre user, enter in psql console
psql foreman

now just run as querys that need it

I got into postgres and no hosts listed by any of the names…still scratching my head…

1 Like

I fixed it by running hammer host list… found the name of the host, then ran hammer host delete --name

2 Likes