Skip to content

Instantly share code, notes, and snippets.

Created August 30, 2020 10:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
an ansible playbook that does semantic version sorting, more here:
- hosts: localhost
- name: Linux | Find all versions of Vagrant
return_content: yes
register: vagrant_index
# this was the original code from here:
# this code doesn't get the most recent version of vagrant
# - name: Linux | Finds the latest version of Vagrant when latest var is define
# set_fact:
# vagrant_version_to_install: "{{ item }}"
# with_items: "{{ (vagrant_index.content | from_json).versions | list | sort | last }}"
# - debug:
# var: vagrant_version_to_install
- shell:
cmd: |
# the set command comes from this:
set -${-//[sc]/}eu${DEBUG+xv}o pipefail
# this assigns everything from stdin to an array value
# got it from here:
IFS=" " read -r -a arrayzz
# then this line reads in that assigned array and sorts the values in the array
# with the latest value being at the top. So, then at the end you print out
# the first value in the array. which should be the latest release.
# got this from here:
IFS=$'\n' sorted=($( sort -t '.' -k1,1nr -k2,2nr -k3,3nr <<<"${arrayzz[*]}" ))
# then you just print out that version so it get put in the register
printf '%s' "${sorted[0]}"
stdin: '{{ (vagrant_index.content | from_json).versions | list | join(" ") }}'
executable: /bin/bash
register: shell_output
changed_when: False
- debug:
var: shell_output
- debug:
msg: '{{ shell_output.stdout }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment