Discovery error: "Validation failed: Name has already been taken"

Problem: Discovery error: “Validation failed: Name has already been taken”

Expected outcome: Discovered facts are sent to foreman. The new host appears in the Discovered hosts

Foreman and Proxy versions: 2.1.1

Foreman and Proxy plugin versions:

  • foreman-tasks 2.0.2
  • foreman_ansible 5.1.1
  • foreman_datacenter 2.0.1
  • foreman_discovery 16.1.0
  • foreman_remote_execution 3.3.5

Distribution and version: CentOS 7.8

Other relevant data:

I have configured one organization with only one location and one domain. There are 2 subnets, no VLANs, no network restrictions.
In the first subnet there is the foreman master with one smart proxy. In the second subnet just the smart proxy (this was needed for the dhcp of the discovered hosts).
The new host is discovered in 2nd subnet, facts are sent directly to foreman master in 1st subnet.

I had this issue initially on one server. I managed to reproduce the issue on a 2nd server.
The discovery was working well for the 2nd server, facts were sent, and the host appeared under “Discovered hosts”.
But, after trying to provision it, I received an error. Did not take a screenshot, but here is the related production.log
The thing is, now the discovery fails with the “Name has already been taken” also for this host.
I tried to manually delete the records associated with the MAC in the foreman DB, using

foremandb=> DELETE FROM fact_values WHERE host_id=511;                                                                                                                                       
foremandb=> DELETE FROM nics WHERE host_id=511;                                                                                                                                              
foremandb=> DELETE FROM hosts WHERE id = 511;                                                                                                                                                

But this did not solve the issue. Once the discovery sends the server details to foreman, new records are created in the DB, discovery fails with the “name already taken” error, and the host does not appear anymore in the Discovered hosts.

My guess is that a failed provisioning from a discovered host generates something invalid inside the DB.

I would like to know if there is a way to properly clean the DB to a good state… to being able to see the new host under the Discovered hosts of foreman.

Discussion was started within this issue

1 Like

Can you share log from the failed provisioning?

@lzap here it is

On the web interface, this error appears

This server has a 4-port 1Gb network card, plus 1 2-port 10Gb network card. When configuring the network, I set to Managed all the interfaces, and add a Bond interface with the 2 ports of the 10Gb NIC.

As an example

Another detail, after running the discovery on a new host. the host of the logs above re-appeared again in the “Discovered host”, and the “Name already been taken” error not appeared any more after a discovery. I’m confused. Can it be my foreman db is in an inconsistent state?

Unfortunately, provisioning over bonds is unsupported. That’s why it fails to save the host and then as a consequence it creates an incorrect host which is blocking discovery :frowning:

@lzap mmm… this is weird.

With a previous version of foreman, I have already configured/provisioned something like 10 servers using this network setup. I had to set Managed + empty every field to every NIC, and then add the bonding interface. And this was working for the provisioning, and also after, the server was properly configured with a bonding interface. Is this a regression added in a recent foreman version?

How can I provision a server, and make sure that after the provisioning it has a working bonding interface?

Is there a way to properly clean the DB to recover the host for which I always get the “Name already been taken” error?

Bonding has never been enabled for downloading the installer, after that this might have worked however this is not a tested scenario.

I don’t know, try to spot a change in provisioning (kickstart) template. There were some changes recently.

Just delete the hosts, they are usually hovering in Any Organization / Any Location.

Thanks for your message @lzap

I managed to properly clean the database.

Regarding the provisioning using a bond interface… since it is not supported, I will move the bonding configuration in a post-install ansible playbook.

In the meantime, I just wanted to let you know that I have found a work-around to provision the server using the bonding interface.

In practice… I booted the server with discovery… all facts retrieved… then… provisioned the server using a single NIC (the one discovery was using too). Then, after the server was provisioned… edited the server in foreman… changed to Managed/None all the NICs, added the bond interface and replaced hostname with hostname-temp and the IP with a temporary one… then restored the correct hostname and IP… and finally foreman was accepting the configuration and the changes, and was allowing me to build the server using the bond interface for the provisioning… yes, I know… I cheated foreman :smiley:

Many thanks for your help!

1 Like