theforeman / foreman_puppet

https://theforeman.org/plugins/foreman_puppet/
GNU General Public License v3.0
7 stars 25 forks source link

Unable to delete host after disabling foreman_puppet (after using it) #331

Open nadjaheitmann opened 1 year ago

nadjaheitmann commented 1 year ago

https://community.theforeman.org/t/unable-to-delete-host-after-disabling-puppet/32112/8

nadjaheitmann commented 1 year ago

Looks like the DB structures are not deleted correctly after the foreman_puppet plugin was in use for some time and the table fills up with data.

ronnybremer commented 1 year ago

Puppet was enabled by default when we installed F/K. After a few years I disabled the plugin and ran the command

foreman-maintain plugin purge-puppet --remove-all-data

according to the documentation. Also ran

foreman-rake purge:puppet

to make sure all is cleaned out.

However, I still find this in the Postgres DB:

foreman=# select count(*) FROM host_puppet_facets;
 count
-------
    19
(1 row)

And apparently an entry in that table prevents a host from being deleted, as the Puppet code (which I assume normally takes care of the cascaded delete) is no longer run.

nadjaheitmann commented 1 year ago

Which initial version of Foreman/Katello did you install?

ronnybremer commented 1 year ago

Ohhh... that was a long time ago, I think F 2.x and K 3.1?

nadjaheitmann commented 1 year ago

Ah, okay. Then the data was already there in the old Foreman and was ported to the plugin once you upgraded Foreman to 3.0.

nadjaheitmann commented 1 year ago

I had a look at the issue but it is somehow difficult to reproduce. Host and hostgroups are being deleted without any errors on my test system.

What I found is that (for some reason I could NOT find), the foreman-maintain command that removes the puppet tables from the database (https://github.com/theforeman/foreman_maintain/blob/v1.0.x/definitions/procedures/puppet/remove_puppet.rb#L15) does not drop the tables for host_puppet_facets and hostgroup_puppet_facets - although the foreman-maintain log tells me that they were dropped. When I check the database, the tables are still there. But when I execute foreman-rake db:migrate VERSION=0 SCOPE=foreman_puppet manually, all tables are dropped from the database as they should.

nadjaheitmann commented 1 year ago

@ronnybremer Did you try to remove the host_puppet_facets and hostgroup_puppet_facets tables manually?

I am not sure if we can reproduce your issue that easily. Do you remember which Foreman version you were on when removing Puppet?

ronnybremer commented 1 year ago

Did you try to remove the host_puppet_facets and hostgroup_puppet_facets tables manually?

No, I only removed the offending records for the one host I tried to remove. The rest is still untouched. Furthermore, I only had a dependency issue with the host_puppet_facets table, but I also didn't try to delete a host group.

nadjaheitmann commented 1 year ago

I think it should be safe to remove the puppet facets tables. If you don't use Puppet and the rest of the plugin is gone anyways, they are no good. Could you check whether there are other artifacts from foreman_puppet that were not removed? Or you can simply post a list of the tables that are available in your setup if that is okay for you.

nadjaheitmann commented 1 year ago

@stejskalleos Could you find someone to test this issue? We could not reproduce. From my perspective, this seems to be a one-time issue with an older system that has used Puppet before transitioning to the foreman_puppet plugin but I'd like someone to double-check.