Improve version checking

Adopt the Ansible conditional checking format of `when: var1 is version(var2, '<') as explained here:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#comparing-versions
This commit is contained in:
Nathaniel Landau
2022-05-12 09:32:53 -04:00
parent 20107b2404
commit 523560d6ef
2 changed files with 12 additions and 7 deletions

View File

@@ -50,6 +50,11 @@
consul_download_uri: "https://releases.hashicorp.com/consul/{{ consul_version }}/consul_{{ consul_version }}_darwin_amd64.zip"
when: mac_intel
- name: "set variable: Set Consul download Binary (MacOSX)"
ansible.builtin.set_fact:
consul_download_uri: "https://releases.hashicorp.com/consul/{{ consul_version }}/consul_{{ consul_version }}_darwin_arm64.zip"
when: mac_arm
- name: Assert that we can install Consul
ansible.builtin.assert:
that:
@@ -227,7 +232,7 @@
- not consul_binary_file_location.stat.exists
- name: Check current version of Consul
ansible.builtin.command:
ansible.builtin.shell:
cmd: /usr/local/bin/consul --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+'
ignore_errors: true
changed_when: false
@@ -243,7 +248,7 @@
when:
- consul_download_uri is defined
- not need_consul_install
- installed_consul_version.stdout != consul_version
- installed_consul_version.stdout is version(consul_version, '<')
- name: install Consul
become: true

View File

@@ -162,7 +162,7 @@
- name: Install or Update Nomad
block:
- name: "set fact: do we need a nomad install?"
set_fact:
ansible.builtin.set_fact:
need_nomad_install: false
- name: Check if nomad is installed
@@ -171,7 +171,7 @@
register: nomad_binary_file_location
- name: "set fact: do we need a nomad install"
set_fact:
ansible.builtin.set_fact:
need_nomad_install: true
when:
- not nomad_binary_file_location.stat.exists
@@ -186,15 +186,15 @@
- not need_nomad_install
- name: "set fact: do we need a nomad install"
set_fact:
ansible.builtin.set_fact:
need_nomad_install: true
when:
- not need_nomad_install
- current_nomad_version.stdout != nomad_version
- current_nomad_version.stdout is version(nomad_version, '<')
- name: install Nomad
become: true
unarchive:
ansible.builtin.unarchive:
src: "{{ nomad_download_file_uri }}"
dest: /usr/local/bin
remote_src: true