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;
DELETE 421
foremandb=> DELETE FROM nics WHERE host_id=511;
DELETE 7
foremandb=> DELETE FROM hosts WHERE id = 511;
DELETE 1
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