Add hosts to host group automatically

Looking at using Foreman/Katello/Ansible as a replacement for Spacewalk. We have a couple hundred Linux VM’s I need to pull into Foreman. I can use subscription-manager and the appropriate activation key to get the system into Foreman. I can also get remote ssh execution working, and can have Ansible talk to the host.

What I’d like to do is have the newly added hosts automatically added to a host group so that they are auto assigned ansible roles for things like domain join, deployment of required applications, and shell environment configuration.

I may be going about this process all wrong. Can anyone set me straight on this?

Thanks!

You may be interested in foreman_hooks and the (soon) future replacement foreman_webhooks plugins. Also take a look at the new registration functionality where you can specify the hostgroup as a parameter for the registration command. This wraps the subscription-manager so would most likely be similar to what you already use.

I can no longer edit my reply, so a bit more clarification

The early demo of the foreman_webhooks that could be used to call back to Foreman and update the hostgroup upon host creation - here. However it does not feel right and I would say is kind of a last resort option.

Perhaps the simplest option is to change your registration process a bit. Take a look at this video, the one I shared in previous post focuses on imlementation instead of the whole flow.

I typically recommend the default_hostgroup plugin. Not very modern, but it does its job! :wink: