Assert using Regex

Hello,

I am able to do the assert using basic string check. But i am looking for a way to do using regex.

example.
i have register: result with below value

“stdout_lines”: [
“microsoft (R) Windows Script Host Version 5.812”,
“Copyright (C) Microsoft Corporation. All rights reserved.”,
“Software licensing service version: 10.0.17763.107”,
“Name: Windows(R), ServerStandard edition”,
“Description: Windows(R) Operating System, VOLUME_MAK channel”,
“Activation ID: xxxxxxxx-e4b1-483b-81e8-xxxxxxx”,
“Application ID: xxxxxxx-d682-4d71-983e-xxxxxxx”,
“Extended PID: 03612-xxxxxx-071-xxxxxx-03-1033-1xxx7763.0000-xxxxx”,
“Product Key Channel: Volume:MAK”,
“Installation ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxx”,
“Use License URL: https://activation-ssssssssssssssss?configextension=Retail”,
“Validation URL: https://validation-v2.sls.microsoft.com/SLWGA/slwga.asmx”,
“Partial Product Key: djkahdjka”,
“License Status: Licensed”,
“Remaining Windows rearm count: 1000”,
“Remaining SKU rearm count: 1001”,
“Trusted time: 5/13/2021 2:51:47 PM”
]

using the code as below i am able to do the assert

  • assert:
    that:
  • “‘License Status: Licensed’ in result.stdout_lines”
  • “‘Product Key Channel: Volume:MAK’”
  • “’ Remaining Windows rearm count: 1000 ’ in result.stdout_lines”
    success_msg: “activated”
    fail_msg: “not activated”

My problem is that i "Remaining Windows rearm count" can be between 1000-2000, do we have way to get this check as right now its static to 1000

regards

Amit

Can uou use >= with 1000

that may not be possible as all of this are string under register.stdout_lines

Adding this to the list of assertions will succeed for number between
1000 and 1999:

- "result.stdout_lines|regex_search('Remaining Windows rearm count: 1\\d{3}')"

Tweak the regex some more to include 2000 itself as well.

You can also first extract that number so you can use the standard >,
< etc tests, for example:

    - set_fact:
        remaining_windows_rearm_count: "{{
result.stdout_lines|regex_replace('.*Remaining Windows rearm count:
(\\d+).*', '\\1' ) }}"

    - assert:
        that:
          - "'License Status: Licensed' in result.stdout_lines"
          - "'Product Key Channel: Volume:MAK'"
          - 2000 >= remaining_windows_rearm_count|int > 1000
        success_msg: "activated"
        fail_msg: "not activated"

Hi Dick,

Sorry for reverting for back late. Thanks a lot for the above sample. this really help me.

Regards
Amit