Bug #25803
closedDuplicate hosts from facts when running Ansible on secondary interface
Description
A new host is created from facts when Ansible is executed on secondary interface.
Steps to reproduce:
1) Create a host with 2 interfaces - one as primary and provision without rex, the other with rex - see screenshots for details
2) Add Ansible role to host and run Ansible
3) notice second host with fqdn of the secondary interface was created
Files
Updated by Arend Lapere over 6 years ago
After doing some preliminary code review on the path followed for the facts import; I've at least got a better understanding on what's going on here. Seems it is expected, by the API, that facts for a none existing host create a new one:
https://github.com/theforeman/foreman/blob/develop/app/controllers/api/v2/hosts_controller.rb#L280
A little bit further down the line, it can be observed that the import_host is being called, which in turn searched either by certname, if it is provided or falls back to a regular "name" search, based upon hostname:
So, looks to me there are 2+1 possibilities:
- Either we adapt the callback script from ansible to always send facts based upon the system's hostname (and not the inventory hostname); but this probably is brittle and there are probably use-cases in which this isn't the safest route to take
- Adapt foreman to look for a host by name, but, in case none is found, try to do a deep search for a hostname associated to any of a host's network interfaces. (Not sure if there is already such a function available). I propose this one, as it is a controlled way moving forward. Tests can be easily written for this and have no further dependencies.
(-) Override the find by name function for a host altogether, making it always look for a hostname on all registered NICs. This would also have, as a side effect, that one could search in the foreman UI for any hostname and it would return the correct host. This might be dangerous and would need a more in depth review before we could think about proposing this one. I just gave this one for completeness sake; in case somebody things this should be the winning proposal.
Thought? Proposals? Recommendations?
(My final 5 cents is, I don't really think this issue is related to just Ansible?)
Updated by Adam Ruzicka over 6 years ago
- Related to Bug #25765: When remote_execution_connect_by_ip is enabled, job output shows ip instead of hostname added
Updated by Ondřej Pražák about 6 years ago
- Status changed from New to Resolved