Failure using mehod (v2_runner_on_ok) in callback plugin <ansible.plugins.callback.foreman.CallbackModule>

Hello,

I’ve setup a test Ubuntu 16.04 VM with Ansible (just 2 small playbooks) which work just fine. Installed and configured Formean (installed the plugins, changed the ansible.cfg file to callback the plugin etc…)

I keep running into the following error whenever I try running a simple playbook

[WARNING]: Failure using method (v2_runner_on_ok) in callback plugin (): HTTPConnectionPool(host='localhost', port=3000):
Max retries exceeded with url: /api/v2/hosts/facts (Caused by NewConnectionError(': Failed to establish a new
connection: [Errno 111] Connection refused',))

Now the issue here is that it keeps trying to access the localhost via port 3000 and no matter what I change it keeps erroring in that port. I’ve looked at the foreman_callback.py script and confirmed that it is listening on 443 but I’ve changed to everything I can think of, port 80, port 3000 (as it looks like that’s what it goes to by default) and nothing works. I’ve disabled the firewall, I’ve even made changes to the apache2/sites-enabled foreman host files but nothing seems to work.

My question is, how do I change that CallbackModule: HTTPConnectionPool to use port=443 or any other port for that matter. It looks like that is the only error I have. I can see that it is gathering the facts but it fails to send it to Foreman because of the incorrect port.

This is the Play Recap I get:

PLAY RECAP ******************************************************************************************************************************************************************************************
ansibletest : ok=2 changed=1 unreachable=0 failed=0
apache : ok=2 changed=1 unreachable=0 failed=0

[WARNING]: Failure using method (v2_playbook_on_stats) in callback plugin (): HTTPConnectionPool(host='localhost',
port=3000): Max retries exceeded with url: /api/v2/reports (Caused by NewConnectionError(': Failed to establish a new
connection: [Errno 111] Connection refused',))

Callback Exception:
File "/usr/lib/python2.7/dist-packages/ansible/executor/task_queue_manager.py", line 375, in send_callback
method(*new_args, **kwargs)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/callback/foreman.py", line 221, in v2_playbook_on_stats
self.send_reports(stats)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/callback/foreman.py", line 199, in send_reports
verify=self.ssl_verify)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 107, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 53, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 437, in send
raise ConnectionError(e, request=request)

[WARNING]: Failure using method (v2_playbook_on_stats) in callback plugin (): 'module' object has no attribute
'dumps'

Callback Exception:
File "/usr/lib/python2.7/dist-packages/ansible/executor/task_queue_manager.py", line 375, in send_callback
method(*new_args, **kwargs)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/callback/init.py", line 376, in v2_playbook_on_stats
self.playbook_on_stats(stats)
File "/home/vagrant/.ansible/plugins/callback_plugins/foreman_callback.py", line 234, in playbook_on_stats
self.send_reports(stats)
File "/home/vagrant/.ansible/plugins/callback_plugins/foreman_callback.py", line 155, in send_reports
log = self._build_log(self.items[host])
File "/home/vagrant/.ansible/plugins/callback_plugins/foreman_callback.py", line 132, in _build_log
'messages': {'message': json.dumps(msg)},

https://theforeman.org/plugins/foreman_ansible/1.x/index.html#2.1Ansiblecallback

Notice the part about setting environment variables to tell the callback where to find the Foreman host and certificates.

You can configure it via the following environment variables (ensure these are set for the user who runs the foreman-proxy or foreman itself):

FOREMAN_URL: the URL of your Foreman installation (default “http://localhost:3000”)
FOREMAN_SSL_CERT: The public key when using SSL client certificates (default “/etc/foreman/client_cert.pem”)
FOREMAN_SSL_KEY: The private key when using SSL client certificates (default “/etc/foreman/client_key.pem”)
FOREMAN_SSL_VERIFY: wether to verify SSL certificates. Use False to disable certificate checks. You can also set it to CA bundle (default is “True”).

Hey @Daniel_Lobato

Thanks for getting back to me. Actually after reading this carefully I see that I don’t need to set that Ansibleback part since my Ansible version is 2.4.2.0 so all I setup in the Ansible Config file is:

bin_ansible_callbacks = True
callback_whitelist = foreman

I run an Ansible playbook and I don’t see anything in Foreman, like the facts so I can see that it is adding the hosts in the Hosts section within Foreman

If you have Ansible 2.4.2.0, you don’t need to download the callback - as you noticed, you can use the options you mentioned in the Ansible Config file.

However, you still need to set these variables, the callback cannot know where your Foreman is located or what certificates to use without that.

hey Daniel!

stupid question but since I don’t use the callback python script (where i could set those variables) where do I set those variables? inside the /etc/ansible/ansible.cfg file? and if so, where exactly? i only see a few options for the callback_plugins. Thanks very much for your help Daniel

Nope, the environment variables have to be set somewhere else. I would recommend /etc/environment if your distribution supports it - most likely yes: (https://unix.stackexchange.com/questions/117467/how-to-permanently-set-environmental-variables)

In /etc/environment:

FOREMAN_URL=yoururl.yourdomain
FOREMAN_SSL_CERT=path/to/ssl_cert
FOREMAN_SSL_KEY=path/to/key

If you are not sure of where your SSL cert and key are located, go look in /etc/httpd/conf.d/05-foreman-ssl.conf (or 05-katello-ssl.conf), or any file in /etc/httpd/conf.d/ which contains something like:

  SSLEngine on
  SSLCertificateFile      "/etc/pki/katello/certs/katello-default-ca.crt"
  SSLCertificateKeyFile   "/etc/pki/katello/private/katello-default-ca.key"

Those are respectively the cert and the key.

I will update the manual in a few days as I see it can be a complicated step for some users, certainly it’s not clear from the current wording how to do it.