In Red Hat Satellite, Immediate API host creation fails with "Validation failed: Name has already been taken" after Hammer deletion
Environment
- Red Hat Satellite 6.16 or later
- Ansible or CI/CD Pipelines
Issue
-
When a host is deleted using the hammer host delete command followed immediately by an API call to recreate the host with the same name, the host creation fails with the following error:
Error Message: HTTP 422 Unprocessable Entity - Validation failed: Name has already been taken -
The host is no longer visible in the Satellite Web UI or via
hammer host list, but the API still considers the name taken. -
This happens when any automated way (be it Ansible, shell script or a CI/CD method) is used to create delete and re-create the host.
Resolution
-
Apply the steps in the Diagnostic Steps section of this solution article to confirm that the solution documented here fits the reported issue. Proceed only if the outcome from the diagnostic steps matches.
-
This bug has been reported to Red Hat Satellite Engineering in the This content is not included.SAT-42156 Jira ticket.
-
To workaround the issue:
i. Delete the existing "ghost" host record by applying Host registration with the Red Hat Satellite server failing with error: Validation failed: Name has already been taken.
ii. Implement a delay or verification step in your CI/CD pipeline:
- Add a wait step: Add a 10–15 second pause between the delete and create commands.
- Use a "until" loop in Ansible to verify the host is actually gone before proceeding:
```
- name: Verify host is purged
shell: "hammer host list --search 'name = {{ host.example.com }}'"
register: host_check
until: host_check.stdout == ""
retries: 5
delay: 5
```
**Note:** The above delay is an example, please apply the sleep timer according to what fits the playbook or automation script being used.
For more KB articles/solutions related to Red Hat Satellite 6.x Provisioning Issues, please refer to the Consolidated Troubleshooting Article for Red Hat Satellite 6.x Provisioning related Issues.
Root Cause
In Satellite 6.16+, host deletion is an asynchronous process involving multiple background tasks (cleaning up content facets, subscription facets, and Puppet certificates).
The hammer host delete command returns a success message as soon as the deletion task is initiated or processed by the primary worker, but the PostgreSQL transaction may not have fully committed. When the API Create request arrives milliseconds later, the database's unique name constraint triggers a validation failure because the old row has not yet been physically purged or the transaction finalised.
Diagnostic Steps
-
Confirm the host is not visible in under
Hosts -> All Hostsin the Satellite's web UI or via thehammer host list --search "name = host.example.com"command. -
Use the Foreman console to check for the host object:
foreman-rake console
Host.unscoped.find_by_name("host.example.com")
If this returns a host object (e.g., #<host.example.com::Managed id: ...>), the record still exists in the database despite being "deleted" in the UI.
- In the Satellite's web UI, check for any active or stuck tasks under
Monitor > Taskswith the labelActions::Foreman::Host::Destroy.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.