how to get DaysLeft value in stdout_line?

Hi,
I need to only get the “DaysLeft” value in my “register” output:

REGISTER:
{
“changed”: true,
“invocation”: {
“module_args”: {
“removes”: null,
“_raw_params”: “wmic /namespace:\\root\CIMV2\TerminalServices PATH Win32_TerminalServiceSetting WHERE (__CLASS !="") CALL GetGracePeriodDays”,
“chdir”: null,
“creates”: null,
“output_encoding_override”: null,
“cmd”: null,
“argv”: null,
“stdin”: null
}
},
“cmd”: “wmic /namespace:\\root\CIMV2\TerminalServices PATH Win32_TerminalServiceSetting WHERE (__CLASS !="") CALL GetGracePeriodDays”,
“rc”: 0,
“stdout”: “Executing (\\SERVER01\root\CIMV2\TerminalServices:Win32_TerminalServiceSetting.ServerName="SERVER01")->GetGracePeriodDays()\r\r\nMethod execution successful.\r\r\nOut Parameters:\r\ninstance of __PARAMETERS\r\n{\r\n\tDaysLeft = 94;\r\n\tReturnValue = 0;\r\n};\r\n”,
“stderr”: “\r\n”,
“start”: “2022-08-29 20:02:32.821675”,
“end”: “2022-08-29 20:02:33.084685”,
“delta”: “0:00:00.263009”,
“stdout_lines”: [
“Executing (\\SERVER01\root\CIMV2\TerminalServices:Win32_TerminalServiceSetting.ServerName="SERVER01")->GetGracePeriodDays()”,
“”,
“Method execution successful.”,
“”,
“Out Parameters:”,
“instance of __PARAMETERS”,
“{”,
“\tDaysLeft = 94;”,
“\tReturnValue = 0;”,
“};”
],
“stderr_lines”: [
“”
],
“_ansible_no_log”: false
}

Playbook:

  • name: output
    debug: msg=“{{ r.stdout_lines.DaysLeft }} days”

Hello, your question seems to be about using Ansible, not about AWX. https://groups.google.com/g/ansible-project is the best place to visit for user questions about Ansible.

That being said, because you used the command module the output comes in two forms stdout and stdout_lines. They are the same just one is a string (stdout) and the other is an array of string (stdout_lines). So you will need to use some string manipulation to get the data. This will be very dependent on how reliable your commands output will be. I would probably just use some regular expressions. Assuming your variable is called “r” you should be able to do something like:

  • name: output
    debug:
    msg: “{{ r.stdout | regex_replace(‘\n’, ‘’, multiline=false) | regex_replace(‘.DaysLeft = ([0-9]+);.’, ‘\1’) }}”

The Ansible group may be able to point you to better methods to achieve this.

-The AWX Team

Thanks!
this worked correctly.
Bye