Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Version comparison fails on things like 1.9 -> 1.10 #5

Open
geerlingguy opened this issue Aug 20, 2021 · 1 comment
Open

Version comparison fails on things like 1.9 -> 1.10 #5

geerlingguy opened this issue Aug 20, 2021 · 1 comment
Labels
bug Something isn't working planned

Comments

@geerlingguy
Copy link
Owner

I just ran this on drupal-vm today and got:

   - name: geerlingguy.java
-    version: 1.10.0
+    version: 1.9.7

So... the version comparison is definitely not working as planned.

@geerlingguy geerlingguy added bug Something isn't working planned labels Aug 20, 2021
@gotmax23
Copy link

Hi Jeff,

I came here after seeing your Ansible Fest presentation. Great job with that, by the way!

- name: Set versions as fact.
set_fact:
role_versions: "{{ (role_metadata.content | from_json).summary_fields.versions }}"
# Note: This is a pretty fragile sort. It works for strict semver... mostly, but
# it might not work with more complex use cases, and Galaxy kind of allows
# anything in the version field, so YMMV. It works with geerlingguy.* roles.
- name: Use the ugliest hack in the world to find the highest version.
set_fact:
highest_role_version: >-
{%- for version_data in role_versions | sort(attribute='name', reverse=True) -%}
{%- if loop.first -%}
{{ version_data.name }}
{%- endif -%}
{%- endfor -%}

It shouldn't even be necessary to sort the data; The versions: array is already sorted properly (i.e. the latest version is the first dictionary in the array).

I plan on creating a PR to address this issue and implement some other ideas I have to make the playbook more structurally sound. I will also take a stab at implementing #1.

I implemented a similar solution to find the latest version of a project on Github in one of my Ansible roles. [link]

Thank you again for all your great Ansible content! Watching/reading your educational content and just looking at your open-source Ansible code has been crucial to my Ansible journey.

-- Maxwell 😀

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working planned
Projects
None yet
Development

No branches or pull requests

2 participants