Existing Host automictically Register as Content Host in Foreman

Hi All,

I am new to Foreman and finally get the foreman and smart proxy doing it’s thing. However, I would like to add a bit of automation so that registering existing hosts to Foreman can be auto.

I know that there is a way to generate a code to register a host to specific content view in GUI. but is there any way I can write an ansible playbook to generate that token and then execute in the ansible host/inventory so that they are registered to Foreman content view without going to GUI?

Tks!

Of course!

We have the registration_command module (theforeman.foreman.registration_command module – Manage Registration Command — Foreman Ansible Modules documentation), which should give you the very same thing as the UI

1 Like

Thanks alot Evgeni.

Unfortunately, I am facing this error when I tried to run the collection to register the host. Is there anything that I should enable in the foreman server so that it will accept an ansible code to run outside of it?

Max retries exceeded with url: /apidoc/v2.json (Caused by NewConnectionError(‘<urllib3.connection.HTTPSConnection object at 0x7fcec6df6310>: Failed to establish a new connection: [Errno -2] Name or service not known’

What did you enter as the sever_url when using that module? It needs to be the URL to your Foreman host.

yes I did confirm that I have already entered the URL correctly. and making sure the admin password is correct too… …

Thanks @evgeni . My bad. I figured it out. the above error that I have encountered was because the target host doesn’t have the foreman server host entry defined in /etc/hosts… The the forman registration collection works great!

1 Like