Error when try to delete a host via GUI or foreman-rake console

Problem:
Error when I try to delete a host.

Expected outcome:
Delete host.

Foreman and Proxy versions:
Foreman nightly
Proxy 2.0.0-develop

Foreman and Proxy plugin versions:

Distribution and version:
Debian Buster

Other relevant data:
foreman-rake console
Host.find_by_name("Loading production environment (Rails 5.2.1)
irb(main):001:0>
irb(main):002:0>
irb(main):003:0> Host.find_by_name(“pc1.mycompany.net”).destroy
Traceback (most recent call last):
2: from lib/tasks/console.rake:5:in `block in <top (required)>’
1: from (irb):3
ActiveRecord::InvalidForeignKey (PG::ForeignKeyViolation: ERROR: update or delete on table “hosts” violates foreign key constraint “targeting_hosts_host_id” on table “targeting_hosts”)
DETAIL: Key (id)=(105) is still referenced from table “targeting_hosts”.
: DELETE FROM “hosts” WHERE “hosts”.“id” = $1

I managed to delete accessing via psql, but it is a lot of work, because I had to delete several entries in several tables.

Would it have another way, in case it happens again?

Is it possible that you at one time had foreman_remote_execution plugin installed and then removed it? That is where this foreign key relation is defined, but it is defines that association to be destroyed when destroying a host so its odd that it didn’t get removed properly when you destroyed the host.

hello @tbrisker, thanks for the answer!!

Exactly! I had foreman remote execution installed and removed it, because in debian there is a bug regarding the concurrent ruby.

What tables does the foreman remote execution create?

There are quite a few tables, columns and associations created by it. Unfortunately we don’t have a good clean-up mechanism for plugin removals currently. You could try going over all migrations in https://github.com/theforeman/foreman_remote_execution/tree/master/db/migrate and reverting them manually, but it is untested. Another approach could be installing remote execution and not using it (and hopefully the concurrent ruby issue will be resolved eventually).

There is this bug that generates an error with each restart of the foreman-proxy.

You don’t have to install remote-execution plugin on the proxy to get the correct db table structure, just on the foreman server

Both are on the same server. How do I what you suggested?

If you are installing using the installer, run foreman-installer --enable-foreman-plugin-remote-execution. If you are installing from packages, run apt-get install ruby-foreman-remote-execution. Note this means you will have remote execution in your menus but it will not be functional until you have a proxy that includes the remote execution function enabled.

By installing only ruby-foreman-remote-execution the foreman-proxy will restart normally. Cool!

Then, the bug occurs by installing ruby-smart-proxy-remote-execution-ssh.

From what I could see on the concurrent ruby’s github, they have already solved the problem with debian. On the foreman’s part there is still something to do. Do you know if they’re already working on it?

I know @aruzicka has been working on it, not sure about the current status.

Ok. Thanks for the help @tbrisker!!! Great day for you!! :+1:

1 Like

Well, yes and no. They made a pre-release which should fix things and as far as I can tell it looks good, but noone packaged it yet. I’m not really a packaging guy, but I think we’re waiting for a proper (non pre-) release to be released.

1 Like

Ok @aruzicka!! Thanks for the feedback!!

Maybe now, it’s released?