Hello
@Marek_Hulan I think there’s a bug in foreman which casues it.
It was reported on the forums many times, e.g.:
I am using Foreman v. 3.13 and theforeman.foreman.host module (theforeman.foreman.host module – Manage Hosts — Ansible Community Documentation) with Ansible and I am experiencing the same problem. I can’t add a host to Foreman, because, allegedly the name is already taken!
So after reading this and other threads I queried the database to check if hosts is added:
select id, name, type, organization_id, location_id from hosts where name like '%ee0407%';
id|name|type|organization_id|location_id
2497|ee0407||1|9
(1 row)
It’s there! Some other host, which is really added to foreman and can see that host in the UI:
select id, name, type, organization_id, location_id from hosts where name like '%ee0408%';
id|name|type|organization_id|location_id
2495|ee0408|Host::Managed|1|9
As you can see the only difference is the type, which is set to Host::Managed.
Now, if host exists in the foreman database, can someone please explain why:
- Host is not being displayed in the gui?
- I can’t retrieve the host details using the foreman API, e.g:
Http get call to: /api/hosts/2497
{
“error”: {“message”:“Resource host not found by id ‘2497’”}
}
- Regardless if host is already to Foreman or not, ansible foreman.host module should be indempotent, right? So if host exists, should update its properties. If not, it should add it. However, it fails with:
“msg”: “Failed to ensure entity state: ForemanApiException: Error while performing create on hosts: 422 Client Error: Unprocessable Content for url: /api/hosts - {‘id’: None, ‘errors’: {‘name’: [‘has already been taken’]}, ‘full_messages’: [‘Name has already been taken’]}”
ID: None, in the result which is weird.
- Adding state: absent to the ansible module doesn’t work:
"changed": false, "diff": { "after": { "hosts": [ {} ] }, "before": { "hosts": [ {} ] } }, "entity": { "hosts": [ null ] },