Getting connection failed for localhost:8081

Foreman 2.1.1 on Centos 7.8
Puppetserver 6.12.1-1

I have hosts that I have built with this version of foreman running centos 7.8 and centos 8.

When I go to the Puppet Classes button (under Details) for any host I get the following error:

Oops, we’re sorry but something went wrong Failed to open TCP connection to localhost:8081 (Connection refused - connect(2) for “localhost” port 8081)

I know at one point puppet ran on port 8081 but this is a brand new install of Foreman so its never been upgraded from an older version of Foreman.

Any clues

Where exactly do you see that error? Is there anything more specific in Foreman’s production.log?

I see that error in the GUI as a popup message. Here is what I see in the production.log at the same time:

2020-08-28T08:39:34 [I|app|e3f4c185] Started GET “/puppetdb_foreman/nodes/” for at 2020-08-28 08:39:34 -0400
2020-08-28T08:39:34 [I|app|e3f4c185] Processing by PuppetdbForeman::NodesController#show as HTML
2020-08-28T08:39:34 [I|app|e3f4c185] Parameters: {“id”=>“”}
2020-08-28T08:39:34 [W|app|e3f4c185] Action failed
2020-08-28T08:39:34 [I|app|e3f4c185] Rendering common/500.html.erb within layouts/application
2020-08-28T08:39:34 [I|app|e3f4c185] Rendered common/500.html.erb within layouts/application (Duration: 4.5ms | Allocations: 1422)
2020-08-28T08:39:34 [I|app|e3f4c185] Rendered layouts/_application_content.html.erb (Duration: 4.1ms | Allocations: 6080)
2020-08-28T08:39:34 [I|app|e3f4c185] Rendering layouts/base.html.erb
2020-08-28T08:39:34 [I|app|e3f4c185] Rendered layouts/base.html.erb (Duration: 6.1ms | Allocations: 7531)
2020-08-28T08:39:34 [I|app|e3f4c185] Completed 500 Internal Server Error in 40ms (Views: 24.5ms | ActiveRecord: 1.8ms | Allocations: 27029)

Does not show much.

Well, it’s a good hint. It looks like you have the PuppetDB plugin installed. That’s probably what’s the service running on port 8081 and can’t be reached.

Well I could have answered that. Yes I have puppetdb plugin installed. To be specific this is what I passed to foreman-installer:

foreman-installer \
--interactive \
--enable-foreman         \
--enable-foreman-cli     \
--enable-foreman-cli-ansible \
--enable-foreman-cli-discovery \
--enable-foreman-cli-remote-execution \
--enable-foreman-cli-tasks \
--enable-foreman-cli-templates \
--enable-foreman-proxy   \
--enable-puppet          \
--enable-foreman-plugin-ansible \
--enable-foreman-plugin-bootdisk \
--enable-foreman-plugin-default-hostgroup \
--enable-foreman-plugin-dhcp-browser \
--enable-foreman-plugin-discovery \
--enable-foreman-plugin-hooks \
--enable-foreman-plugin-monitoring \
--enable-foreman-plugin-puppetdb \
--enable-foreman-plugin-remote-execution \
--enable-foreman-plugin-setup \
--enable-foreman-plugin-snapshot-management \
--enable-foreman-plugin-statistics \
--enable-foreman-plugin-tasks \
--enable-foreman-plugin-templates \
--enable-foreman-proxy-plugin-ansible \

When I go to Administrator -> About in the GUI and look at the Smart Proxies Its showing a status of Green. So I think puppetdb smart proxy should be running. And if I run a ps -ef I see puppet and the puppet agent running.

The PuppetDB plugin doesn’t use a Smart Proxy - it directly connects to PuppetDB. I’d ensure the service is running and nothing blocks it. For example, it may be a firewall or SELinux.

Both SELinux and the Firewall were disabled in the initial kickstart that built the base OS for the the Foreman server.

I have confirmed with iptables -L and sestatus.

By default nothing in the Foreman infra runs on port 8081, only PuppetDB. You should really verify whether it’s running and can connect to it. A simple telnet or openssl s_client is probably sufficient.

Doing a netstat -an |grep 8081 I can clearly see the port is not there.

If I do an rpm -qa|grep puppet. I see that this was installed tfm-rubygem-puppetdb_foreman-5.0.0-2.fm2_1.el7.noarch. But then if I look in the GUI under Administrator -> Settings -> PuppetDB I see PuppetDB API Version = v4: PuppetDB 4.0, 4.1, 4.2, 4.3

How do I manage (start / stop) the puppetDB?

PuppetDB is a separate service. If you’re not running it, then you should not install the Foreman plugin for it. The installer doesn’t support setting it up, but does have support to integrate with it if desired.

So should I remove puppetdb? And if so is that as simple as yum remove tfm-rubygem-puppetdb_foreman???

I think that with that particular plugin it works because there’s no database modifications. Also note you need to call the installer with --no-enable-foreman-plugin-puppetdb to stop it from attempting to install it again next time.

I just rebuilt the server.