From 161456c7f641fdcc1a3fa970b565167a2c8ff624 Mon Sep 17 00:00:00 2001 From: Ruben Ruiz de Gauna Date: Mon, 8 Jan 2024 14:45:42 +0100 Subject: [PATCH] NR-164383 feat: assert version on Windows --- caos.ansible_roles/roles/assert_version/README.md | 13 ++++++++++++- .../tasks/assert-version-Win32NT.yaml | 14 ++++++++++++++ .../roles/assert_version/vars/main.yaml | 5 +++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 caos.ansible_roles/roles/assert_version/tasks/assert-version-Win32NT.yaml diff --git a/caos.ansible_roles/roles/assert_version/README.md b/caos.ansible_roles/roles/assert_version/README.md index 748ad89..e34620b 100644 --- a/caos.ansible_roles/roles/assert_version/README.md +++ b/caos.ansible_roles/roles/assert_version/README.md @@ -1,6 +1,7 @@ Assert application version. ```yaml +# Linux - name: assert version include_role: name: caos.ansible_roles.assert_version @@ -10,4 +11,14 @@ Assert application version. version: "1.36.1" - exec: "otelcol-contrib --version" version: "0.70.0" -``` \ No newline at end of file + +# Windows + +- name: Assert version + include_role: + name: caos.ansible_roles.assert_version + vars: + target_versions: + - exec: '"C:\Program Files\New Relic\newrelic-infra\newrelic-infra.exe" "--version"' + version: "1.47.2" +``` diff --git a/caos.ansible_roles/roles/assert_version/tasks/assert-version-Win32NT.yaml b/caos.ansible_roles/roles/assert_version/tasks/assert-version-Win32NT.yaml new file mode 100644 index 0000000..03f219b --- /dev/null +++ b/caos.ansible_roles/roles/assert_version/tasks/assert-version-Win32NT.yaml @@ -0,0 +1,14 @@ +--- + +- name: Assert expected version + ansible.windows.win_command: '{{ item.exec }}' + register: check + loop: "{{ target_versions }}" + +- name: Stdout from version grep + ansible.builtin.assert: + that: "{{ item.stdout | regex_search('([0-9\\.]+)', '\\1') | first == item.item.version }}" + fail_msg: "{{ item.stdout | regex_search('([0-9\\.]+)', '\\1') | first }} does not match {{ item.item.version }}" + loop: "{{ check.results }}" + +... diff --git a/caos.ansible_roles/roles/assert_version/vars/main.yaml b/caos.ansible_roles/roles/assert_version/vars/main.yaml index 3a26c72..3bea5f3 100644 --- a/caos.ansible_roles/roles/assert_version/vars/main.yaml +++ b/caos.ansible_roles/roles/assert_version/vars/main.yaml @@ -1,8 +1,13 @@ --- +# Linux #target_versions: # - exec: "/usr/bin/newrelic-infra --version" # version: "1.34.0" +# Windows: +# - exec: "C:\Program Files\New Relic\newrelic-infra\newrelic-infra.exe" "--version" +# version: "1.34.0" +# target_versions: [] ...