to my knowledge, there is no way to completely remove a host from Foreman from the managed hosts side.
The commands you are using remove the subscription related part of a Foreman/Katello host, but the “Foreman only” parts (provisioning, config management, etc) stay untouched.
What exactly are you trying to achieve? Maybe there is another way to get there.
I’m using molecule to test a variety of ansible roles. As part of that process, I create a host, test my ansible stuff, then destroy the host. Since this host is ephemeral and only used for testing, I would like to be able to remove it completely from foreman when I’m done using it, and it would be ideal if I can do that from the host itself, rather than manually interacting with Foreman each time I do a build/test/destroy cycle. This is just one example – we have several similar efforts going on simultaneously, so we wind up with a variety of “ghost hosts” in Foreman.
Is there a way to delete an ephemeral host from Foreman, but initiating that deletion from the host itself?
The easiest way to achieve this would probably be to use Foreman’s REST API.
The API Documentation for Foreman and all your installed Plugins can be found under http://your-foreman.example.com/apidoc. The API endpoint DELETE /api/hosts/:id should be what you are looking for. That should delete the host and all associated objects.
You’re welcome
The API documentation is also available somewhere online, though the docs on your own instance have the added upside that they include all your plugins (and only those) and are always the right one for your current version.
Please mark the thread as solved if you are happy with that solution so others know a solution has been fund (The “checkbox” icon on the post with the solution). Thanks
Ah, that’s a good idea as well! In this particular case, I think the API approach will be a better fit, but I can definitely see the value of using the ansible modules as well. Thanks for the heads-up!
There is also a setting if you REALLY want to Delete a host from subscription-manager:
Go to Administer > Settings > Content
Flip ‘unregister_delete_host’ to true.
Note that if you are using a virtual managed provisioned by foreman, that vm will get deleted! Generally this setting should be avoided unless you are aboslutely sure it meets your workflow needs. It is also a server-wide setting, so would apply to ALL subscription-manager unregister commands’