-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
operatingsystems ambiguity #1401
Comments
I think your yaml is wrong. Shouldn't it be - role: theforeman.foreman.operatingsystems
vars:
foreman_operatingsystems:
- name: "AlmaLinux"
major: "8"
description: "AlmaLinux 8"
os_family: "Redhat"
architectures:
- "x86_64"
password_hash: "SHA256"
media:
- "AlmaLinux 8"
- "Local AlmaLinux 8"
- name: "AlmaLinux"
major: "8"
minor: "5"
description: "AlmaLinux 8.5"
os_family: "Redhat"
architectures:
- "x86_64"
password_hash: "SHA256"
media:
- "AlmaLinux 8"
- "Local AlmaLinux 8" |
Yes. You are right. I was already wondering why I got this error. Initially it was a different one which I now get again:
In check mode it looks as if it wants to create a new entry even though it already exists... Both operating systems already exist on the server. |
can you show us the output of |
Here is the output from my new server:
|
Oooh, mhh. Operating systems in Foreman are super weird, so we have some crude logic to search for them. It goes essentially like this: "try to find by description, if that fails, look up by name/major/minor". Now your playbook sets description to "AlmaLinux 8" but the currently existing OS doesn't have that set, so it's not finding it by that (fine!). Next it should try name/major/minor (you didn't set minor, so that would be not taken into the search), so the search string should be The 8.5 search works, as there it already finds it by description. (Did I mention I hate how OSes are implemented?) |
Got it! It searches for "name=AlmaLinux,major=8", but that returns two results, and thus it discards the result. |
diff --git plugins/modules/operatingsystem.py plugins/modules/operatingsystem.py
index 69d70d3d..0be9e478 100644
--- plugins/modules/operatingsystem.py
+++ plugins/modules/operatingsystem.py
@@ -211,7 +211,7 @@ def main():
entity = None
# If we have a description, search for it
if 'description' in module_params and module_params['description'] != '':
- search_string = 'description="{0}"'.format(module_params['description'])
+ search_string = 'description="{0}" or title="{0}"'.format(module_params['description'], module_params['description'])
entity = module.find_resource('operatingsystems', search_string, failsafe=True)
# If we did not yet find a unique OS, search by name & version
# In case of state == absent, those information might be missing, we assume that we did not find an operatingsytem to delete then This should fix the issue for you. |
Shouldn't it possible to distinguish between searching for major=8,minor=null and major=8,minor=*? |
See my explanation in #1407 on why this is not as trivial as it sounds (TL;DR: minor can be null, minor can be an empty string) |
Oh, actually, it can not. It's always an empty string then: |
SUMMARY
Running against a katello 4.3 or 4.4 server my playbook complains about the operating systems to be created/updated:
It seems the problem is that multiple operating systems can have the same name, e.g. AlmaLinux. I have AlmaLinux with major version 8 and no minor version (AlmaLinux 8) and one with minor version 5 (AlmaLinux 8.5)
When adding and syncing AlmaLinux repositories it automatically generates a distribution and operating system "AlmaLinux 8".
The a client host with AlmaLinux 8.5 is registered it automatically generates an operating system "AlmaLinux 8.5" (from puppet facts or subscription manager?)
So this scenario seems standard.
ANSIBLE VERSION
COLLECTION VERSION
Using latest version 3.3.0 from ansible-galaxy with some patches from pull requests.
KATELLO/FOREMAN VERSION
STEPS TO REPRODUCE
Playbook
EXPECTED RESULTS
No error and correct configuration of all operating system entities.
The text was updated successfully, but these errors were encountered: