Katello / katello-client-bootstrap

Bootstrap Script for migrating systems to Foreman & Katello
GNU General Public License v2.0
52 stars 63 forks source link

Hostgroups #341

Closed MaxDiOrio closed 3 years ago

MaxDiOrio commented 3 years ago

OK - so I had an issue with DuplicateName Already Exists when running the script on an existing virtual machine - attempting to register it to Foreman/Katello using the bootstrap script. It was trying to create a brand new VM when it was creating the client in Foreman. From what I gather, I need to skip the foreman section. I also have puppet set to noop. But it looks like it doesn't install puppet - for some reason the repo isn't showing up on the client.

I did this, and I can see the client in Foreman, but the client is never added to the Hostgroup. I need this so that it can be assigned Ansible roles that need to run on it automatically after being added to Foreman.

Am I missing something?

evgeni commented 3 years ago

It shouldn't try to create a new VM, as we're passing build=False to the API. But things might have changed since I last tried that particular feature.

If you're skipping Foreman, the machine won't be added to a hostgroup, so that's probably not what you want.

Can you show me the full call of bootstrap.py that you use when you get the name already exists error, plus the part of /var/log/foreman/production.log that corresponds to it (or the full file?)

Feel free to mail it to evgeni at redhat dot com if you don't want to post it publicly.

B3DTech commented 3 years ago

OK - so this time I tried to deploy I didn't get the hostname already exists, but, it still creates a VM, leaves it powered off, and appears to associate the created VM with the host, as it's showing it's powered off.

image

I think because of this, the actual VM I'm attempting to join isn't getting the correct repos somehow. For example, 'yum repolist' is missing the puppet repository assigned in the activation key, so the script is failing on the puppet install.

I'm calling the bootstrap.py with:

/usr/local/bin/botstrap.py -l foreman -p foreman -s hq-1pforeman.internal.domain.com -o Default_Organization -L DefaultLocation -g DevPortal-CentOS-7 -a DevPortal-CentOS-7 --update --rex --rex-user root --rex-proxies hq-1pforeman.internal.domain.com --puppet-noop --download-method http

I'll email you the production.log file

Thanks!

evgeni commented 3 years ago

Thanks!

Can you please try the following patch?

diff --git bootstrap.py bootstrap.py
index 0e27e49..2c6a823 100755
--- bootstrap.py
+++ bootstrap.py
@@ -915,7 +915,7 @@ def create_host():
     architecture_id = return_matching_foreman_key('architectures', 'name="%s"' % ARCHITECTURE, 'id', False)
     host_id = return_matching_foreman_key('hosts', 'name="%s"' % FQDN, 'id', True)
     # create the starting json, to be filled below
-    jsondata = {"host": {"name": HOSTNAME, "hostgroup_id": myhgid, "organization_id": myorgid, "mac": MAC, "architecture_id": architecture_id, "build": False}}
+    jsondata = {"host": {"name": HOSTNAME, "hostgroup_id": myhgid, "organization_id": myorgid, "mac": MAC, "architecture_id": architecture_id, "build": False, "compute_resource_id": None}}
     # optional parameters
     if my_content_src_id:
         jsondata['host']['content_facet_attributes'] = {'content_source_id': my_content_src_id}
B3DTech commented 3 years ago

That worked for preventing the new VM from spinning up. Thank you.

Now I just need to figure out why a few of my repositories are refusing to show up on the clients and why the Ansible jobs don't run. Could be because the bootstrap script doesn't finish.

It's currently failing on installing katello-host-tools. The repo shows up in the content host, fails to show up in subscription-manager repos though. Ugh....

evgeni commented 3 years ago

Missing subscription in the activation key for that product/repo would be the first thing I'd look for.

B3DTech commented 3 years ago

Activation key is fine. Subscriptions are there, and the repositories are showing up in the repository sets when filtered to limit to environment.

When looking at the content host, I see the same, subscriptions are there and they are there when viewing the repository sets filtered to limit to environment.

In the client rhsm log, I see it updating the certificates for all 7 subscriptions.

B3DTech commented 3 years ago

So I've narrowed it down. It only impacts repositories that I have OS restrictions on.

For example, EPEL.

I have one Product, EPEL. Within that product, I have two repositories. One for CentOS 7, one for CentOS 8. Each repo I have OS restrictions enabled to rhel7 and rhel8. Can I assume that the restriction does not apply to CentOS then?

B3DTech commented 3 years ago

That was it - it is only for RHEL subscriptions.

evgeni commented 3 years ago

nice! yeah I haven't played with those restrictions yet, but that's certainly not bootstraps "fault" ;)

I've opened https://github.com/Katello/katello-client-bootstrap/pull/342 to get that VM part fixed and hope you're settled now?

B3DTech commented 3 years ago

We're all good now. Thanks for the help!

evgeni commented 3 years ago

Absolutely!

If you want, open an issue on https://projects.theforeman.org/ against Katello that those restrictions should not be setable for repos that are not restrictable ;)