Entered organization is lost after discovery

Hi all,


I’m using foreman with salt and the discovery plugin. I’m running into a strange problem with the webinterface, where the organization is changed unexpectedly.

The scenario is as follows:

  1. I’m using the discovery plugin to discover hosts.
  2. After discovery, I select “Provision” for a host using the foreman webinterface.
  3. The webinterface ask me to enter the: Host Group, Organization, and Location.
  4. I have muliple organizations (say A to Z), so I select the last of the available organizations (Organization Z).
  5. Next I create the host and edit some more properties (but I forget one of the required properties, e.g. password field)
  6. After that press submit.
  7. The webinterface nicely tells me that I forgot to enter some fiels, by returning to the “Edit” page for the given node and showing the forgotten field with red borders.
  8. I fill in the forgotten fields and submit again.
  9. Now the webinterface accepts it and starts to build the host.
  10. However, foreman unexpectedly has added the host to the very first organization: Organization A.

It seems related to re-entering the “Edit” page. Because when I enter all the fields correctly and submit, the issue does not occur.

It is tricky though, because you hardly notice that you submitted something else than expected.

Expected outcome:

The host should have been in Organization Z.

Foreman and Proxy versions:

Tried multiple versions with the same outcome:

foreman: 1.14.3 and 1.16.0
foreman_discovery: 8.0.1 and 10.0.0
foreman_salt: 8.0.2 and 9.0.0

Other relevant data:

I did a little digging by looking at the http requests. I noticed that on submit the interface execute a http PUT to /salt/minions/salt_environment_selected.

When entering the form fields correctly, such that the webinterface does not return to the “Edit” page, to send data contains:


However when I forget the enter a required field, such that the webinterface does return to the “Edit” page, these two variables are missing in the http PUT to /salt/minions/salt_environment_selected.

This is a bug and unfortunately there is not easy fix - taxonomy is no longer editable on Edit Host form and we “trick” the form and change the taxonomy via Javascript when you arrive on the form for the first time.

We tried to enable those disabled fields because when provisioning discovery host it should be actually editable but it did not work. If anyone wants to try, patch is welcomed. Keep in mind that katello plugin might change the behavior of taxonomy and the patch must work with and without katello.

Thanks for the reply. I suppose I should write a bug report?

Would it be possible to apply the same ‘trick’ when the foreman interfaces services the ‘Edit Host’ form for a second time? (it is probably not ideal, but at least it is less destructive to the end result)

I would like to apply a patch if I could, but I’m not that familiar with the internals of foreman, foreman_salt and the discovery plugin. Could you give some pointers where to start digging?

You can, associate it with this one please:


But I think the key is to fix this one first in order to have your problem fixed - the issue is taxonomy is somehow ignored.

I created the following issue to cover this: Bug #23193: Entered organization is lost after discovery - Discovery - Foreman

Providing a patch seems a bit difficult though, based on the current information (being relatively new to this). It sounds like the cause may be very deep in the foreman internals itself.

Yes this one is tricky, I failed but I am not an expert of any kind…

I did a little more digging and I noticed that with this particular change, the issue doesn’t occur anymore:

--- foreman_discovery-8.0.1/app/controllers/discovered_hosts_controller.rb.org   2018-05-09 14:41:52.796434461 +0000                                                                                       
+++ foreman_discovery-8.0.1/app/controllers/discovered_hosts_controller.rb       2018-05-09 14:42:32.380434461 +0000                                                                                       
@@ -62,10 +62,11 @@ class DiscoveredHostsController < ::Appl                                                                                                                                               
   def update                                                                                                                                                                                              
     @host = ::ForemanDiscovery::HostConverter.to_managed(@host, true, true, discovered_host_params_host)                                                                                                  
+    @override_taxonomy = true                                                                                                                                                                             
   def perform_update(host, success_message = nil)                                                                                                                                                         
     Taxonomy.no_taxonomy_scope do                                                                                                                                                                         

It is probably not the perfect solution, but maybe it helps to find the real cause.

Can you share the patch again? Seems unreadable.

An artifact of the data import. I can probably fix it, give me a moment… EDIT: yep, found it, done. Sorry about that.

Thanks for fixing it @Gwmngilfen.

@lzap: I assume that the patch above works for you now. Please let me now if you need anything else.

Can you send us a PR? I will test this.

As requested: https://github.com/theforeman/foreman_discovery/pull/433


Sorry for the huge delay. It works great, thank you this was pain in the … ! Good job there. Merged!

Thanks for the merge. One less problem to worry about.

1 Like