Ansible callback with windows openssh.server produces a 500 Server Error: Internal

Have you restarted this? Tests were passing, so it worked on our end.

Hi,

I have the exact same problem.
I tried the modification in ansible_fact_parser.rb, but it didn’t work (no change in log).

Do I need to do something else except restart foreman to assure the modification is used ?

I tried to do just : return
but same

I have foreman 3.0.1

Thanks in advance.

Upgrade to 3.1 or apply this patch:

1 Like

Might be a different problem. Investigate logs on what is wrong, enable debug to see more.

When examining production.log, I found the following error :

NoMethodError: undefined method `match' for #<ActiveSupport::HashWithIndifferentAccess:0x00007fa392c404e0>
/usr/share/foreman/app/services/fact_parser.rb:187:in `block in remove_ignored'

It seems the error is during the callback from ansible to foreman, in /usr/share/foreman/app/services/fact_parser.rb when executing :

def remove_ignored(interfaces)
    interfaces.clone.delete_if do |identifier|
      if (remove = identifier.match(ignored_interfaces))
        logger.debug { "skipping interface with identifier '#{identifier}' since it was matched by 'ignored_interface_identifiers' setting " }
      end
      remove
    end
  end 

Thanks in advance.

PS : I’ve tried to update to 3.1, but I got the following error :

yum update https://yum.theforeman.org/releases/3.1/el8/x86_64/foreman-release.rpm
yum update https://yum.theforeman.org/katello/4.3/katello/el8/x86_64/katello-repos-latest.rpm
yum clean all
yum update

Error:
Problem: package cloud-init-21.1-11.el8.noarch requires python3-jsonschema, but none of the providers can be installed

  • package python38-jsonschema-3.2.0-6.el8.noarch obsoletes python3-jsonschema < 3.2.0-6.el8 provided by python3-jsonschema-3.2.0-4.el8.noarch
  • package python38-jsonschema-3.2.0-6.el8.noarch obsoletes python3-jsonschema < 3.2.0-6.el8 provided by python3-jsonschema-2.6.0-4.el8.noarch
  • cannot install the best update candidate for package python3-jsonschema-3.2.0-4.el8.noarch
  • cannot install the best update candidate for package cloud-init-21.1-11.el8.noarch

So, I’m waiting for an update to hopefully solve this problem.

Here is an idea - what Ansible reports in ansible_os_family? We only test for “Windows” but what if you have something like “Windows 2025 Super Duper Enterprise”, that would not match.

But you said you already put return [] into the method, then explain me how would Ruby interpreter reach that line?

I don’t know ruby, I tried return [] from your patch, just to avoid ansible_os_family having another value (and I don’t know how to find the returned one). I don’t even know if the syntax is correct, I just assume (but I test with the correct line from the patch before that).

I’m not sure I have the necessary skill to answer your question, but my understanding is :

in fact_parser.rb, in function suggested_primary_interface, it calls the function interfaces, which purpose is to gather lists of network interfaces from hosts.
The functions interfaces calls get_interfaces, which is overridden by the def in ansible_fact_parser.rb

So, your patch seems exactly what’s needed.

Is something necessary for the modification to be effective ? I restart foreman :

foreman-maintain service restart

but perhaps something else is necessary (emptying a cache …).

I’ve already open a ticket in 2019 about that problem : Run ansible role in foreman : gathering fact : 500 Server Error: Internal Server Error for url: /api/v2/hosts/facts
But I’ve got no answer at that time. I just tried my luck again with this ticket.

Thanks for answering.

Restarting should be enough really. Are you sure you edited the correct file? On the correct server?

I’ve modify /usr/share/foreman/app/services/ansible_fact_parser.rb :

  def get_interfaces
    return []
    pref = facts[:ansible_default_ipv4] &&
        facts[:ansible_default_ipv4]['interface']
    if pref.present?
      (facts[:ansible_interfaces] - [pref]).unshift(pref)
    else
      ansible_interfaces
    end
  end

And I verify it’s on the correct server.

After you restarted the server, can you share the stacktrace of the error again? Also pastebin the whole file so I can match the line numbers just to be sure.

Hello there,

I’m on Foreman 3.4 and also have problem with this to work on Windows machines. Windows hosts have been created in Foreman after running the playbook but no facts have been gathered (in the end of playbook output I’ve got [WARNING]: Sending data to Foreman at (…) failed for (…): 500 Server Error: Internal Server Error for url). How may I be useful in solving this issue?

Can you share the full stacktrace seen in /var/log/foreman/production.log?

When I try to upload /var/log/foreman/production.log here I receive “Sorry, new users can not upload attachments.”

You can mail it to me to evgeni at redhat dot com if you want to, and I’ll upload it.

Done, email sent.
Thank you.

Okay, the relevant part seems to be:

2022-10-20T13:23:51 [I|app|d3408894] Started POST "/api/v2/hosts/facts" for 192.168.1.90 at 2022-10-20 13:23:51 +0200
2022-10-20T13:23:51 [I|app|d3408894] Processing by Api::V2::HostsController#facts as JSON
2022-10-20T13:23:51 [I|app|d3408894]   Parameters: {"name"=>"win10test002.testdom.local", "facts"=>"[FILTERED]", "apiv"=>"v2", "host"=>{"name"=>"win10test002.testdom.local"}}
2022-10-20T13:23:52 [I|app|d3408894] Import facts for 'win10test002.testdom.local' completed. Added: 100, Updated: 0, Deleted 0 facts
2022-10-20T13:23:52 [W|app|d3408894] Action failed
2022-10-20T13:23:52 [I|app|d3408894] Backtrace for 'Action failed' error (NoMethodError): undefined method `tr' for nil:NilClass
 d3408894 | Did you mean?  try
 d3408894 | /usr/share/foreman/app/services/foreman_ansible/operating_system_parser.rb:82:in `os_name'
 d3408894 | /usr/share/foreman/app/services/foreman_ansible/operating_system_parser.rb:7:in `operatingsystem'

Which is this code:

The ansible_os_family seems to be set to Windows for you, but ansible_os_name is nil and that means no tr on it. Makes sense.

If I create patches, would you be able and willing to test them out?

Also, just to make sure.
Which Ansible version are you running this with?
Also, are you running this with Admin privileges on the Windows machine, or without?

Looking at ansible.windows/setup.ps1 at 9d423ba192081866a67c35ce8f12016c5722b47a ¡ ansible-collections/ansible.windows ¡ GitHub it seems like the os_name and distribution facts are only present when you have Admin rights :frowning:

If you get a chance, could you test this patch?

It will only detect the system as a rather generic “Microsoft Windows” but IMHO better than failing :slight_smile: