Running Ansible Roles creates duplicate hosts

Problem:
When I run Ansible roles on host it will create a 2 additional hosts each time with the same name in Foreman.
The Ansible roles (or the Job & tasks) themself finish ok, with just a

427: 403 Client Error: Forbidden
428: Exit status: 0

as last 2 lines.

Output of hammer after 2 runs:
—|--------------------------|-----------------------------------------------------|--------------------------------|-----------------|-------------------|--------------

ID NAME OPERATING SYSTEM HOST GROUP IP MAC GLOBAL STATUS
40 etta-filary 192.168.221.167 00:50:56:a5:a4:bb OK
34 etta-filary Red Hat Enterprise Linux Server release 7.6 (Maipo) DevOps RedHat Family Templates 192.168.221.167 00:50:56:a5:a4:bb OK
41 etta-filary OK
36 etta-filary 192.168.221.167 00:50:56:a5:a4:bb Error
37 etta-filary Error
-------------------------- ----------------------------------------------------- -------------------------------- ----------------- ------------------- --------------

Expected outcome:
Ansible roles are executed and no new host is created in Foreman, but the collected facts are merged to existing host.

Foreman and Proxy versions:
foreman-1.20.2-1.el7.noarch
foreman-cli-1.20.2-1.el7.noarch
foreman-debug-1.20.2-1.el7.noarch
foreman-installer-1.20.2-1.el7.noarch
foreman-postgresql-1.20.2-1.el7.noarch
foreman-proxy-1.20.2-1.el7.noarch
foreman-selinux-1.20.2-1.el7.noarch
foreman-vmware-1.20.2-1.el7.noarch
tfm-rubygem-foreman_ansible-2.2.11-2.fm1_20.el7.noarch
tfm-rubygem-foreman_ansible_core-2.1.2-2.fm1_20.el7.noarch
tfm-rubygem-foreman_bootdisk-14.0.0-1.fm1_20.el7.noarch
tfm-rubygem-foreman_remote_execution-1.6.7-1.fm1_20.el7.noarch
tfm-rubygem-foreman_remote_execution_core-1.1.4-1.el7.noarch
tfm-rubygem-foreman-tasks-0.14.3-1.fm1_20.el7.noarch
tfm-rubygem-foreman-tasks-core-0.2.5-2.fm1_20.el7.noarch
tfm-rubygem-foreman_templates-6.0.3-2.fm1_20.el7.noarch
tfm-rubygem-hammer_cli_foreman-0.15.1-1.el7.noarch
tfm-rubygem-hammer_cli_foreman_tasks-0.0.13-1.fm1_20.el7.noarch
tfm-rubygem-hammer_cli_foreman_templates-0.1.2-1.fm1_20.el7.noarch

Foreman and Proxy plugin versions:

Other relevant data:
[e.g. logs from Foreman and/or the Proxy, modified templates, commands issued, etc]
(for logs, surround with three back-ticks to get proper formatting, e.g.)

logs

Ansible like all other configuration management will create hosts if not already existing when sending a report to Foreman. So I would guess it is not reporting the “same” host likely because it sends shortname as hostname and not the fqdn.

You’re right, we got the same problems last year. We decided to deactivate the option of creating a new host automatically

@Dirk
Right, I expect that. However the host name is the same.
Host with ID 34 is the ‘original’ one created during ‘Create Host’ process. ID 36+37 created during 1st Ansible Roles play and 40+41 created during 2nd Ansible Roles play.

Since the Web UI calls delete by host name, clicking ‘delete’ on any of the host always deletes the first one by ID. i.e. in this case #34

But thanks to your comment this got me thinking that I haven’t saw this behaviour when using FQDN instead of shortnames. Because this instance of Foreman has ‘Append domain names to the host’ set to No. The default is Yes.

So I did some testing and replicated the issue once more with ‘Append domain names to the host’ set to No. Then set ‘Append domain names to the host’ to Yes and tried again. No duplicate hosts this time.

Any update on this ?

I think here is the answer for that:
https://www.theforeman.org/plugins/foreman_ansible/3.x/index.html#3.Configuration