Foreman ansible facts callback 422 Client Error: Unprocessable Entity for url:

The latest docs seem to be missing something about getting the fact callback working.
Also, they seem to have outdated info.

Foreman :: Plugin Manuals

mentions having to edit /etc/ansible/ansible.cfg , to created a “callback_whitelist”, and related edits.

However, the latest code (foreman 2.4, foreman-ansible gem 6.2) appears to automatically generate an ansible.cfg override, in
/etc/foreman-proxy/ansible.cfg
that appears to have all that info, including valid ssl certs. So that editing seems to not be needed?

That being said… doing an ansible job run to a test client, still has an error at the top of the output,

TASK [Gathering Facts] *********************************************************
ok: [foremanansibletest]
422 Client Error: Unprocessable Entity for url: https://xxx.xxx.com/api/v2/hosts/facts

I am presuming that foreman ansible already uses /etc/foreman-proxy/ansible.cfg as an override, but I tried copying it to /etc/ansible/ on the foreman proxy/server.
It made no difference.

This should not be an issue for ansible caller not in “Trusted hosts”, because I am calling ansible through the foreman-ansible proxy, not by hand.
(and I also tried adding it redundantly to the Trusted hosts list. Didnt help)

Any suggestions as to what I am missing?
(and ideally, a pointer to an up-to-date guide on setting up foreman-ansible fully?)

Hi,
how did you install your Foreman instance? If you used the installer, then you shouldn’t need to fiddle with the config files yourself.

In any case, since you get 422 it means it actually hits the server. Could you paste relevant parts of the logs from the server?

1 Like

HUhhh. Well, this was a surprise.

background:
yes I used the foreman-installer program to install.
I should mention that my intent is for an all-ansible system, but I know that the installer itself uses puppet, so I didnt use the -no-enable-puppet flags for it.
But I didnt define any puppet classes or environment in foreman.

So, when I used the “register host” button (rather than “create host”) and did the curl -X registration, I wasnt too surprised that the host got stuck in “build pending” mode. I ignored it and moved on, focusing on ansible.

What I AM surprised by, is that when I checked the main foreman logs, I saw that fact gathering was denied by build pending.

2021-04-29T06:14:36 [I|app|07f51306] Started POST “/api/v2/hosts/facts” for X.X.X.X at 2021-04-29 06:14:36 -0700
2021-04-29T06:14:36 [I|app|07f51306] Processing by Api::V2::HostsController#facts as JSON
2021-04-29T06:14:36 [I|app|07f51306] Parameters: {“name”=>“foremanansibletest”, “facts”=>"[FILTERED]", “apiv”=>“v2”, “host”=>{“name”=>“foremanansibletest”}}
2021-04-29T06:14:36 [W|app|07f51306] ERF42-9911 [Foreman::Exception]: Host is pending for Build

When I manually cancelled the build on the host, it magically then picked up the facts it wanted, and everything was happy.

Do you have any suggestions for me on what knob I could turn, so that newly registered hosts dont get stuck in this Build Pending state without intervention?

Had the same issue after registering the host,
when trying to run the ansible roles on the host I got this error,
found this post, and canceled the build - and it worked! thanks @pbrown.m