## Convert stdout_lines into json format ##

162 views
Skip to first unread message

Monohar Krushna Behera

unread,
Nov 22, 2019, 8:06:46 AM11/22/19
to Ansible Project
Hi Team,
Greetings of the day!!!

Is there any module or plugin available through which we can convert the stdout_lines of a win_shell output into json data.
if it is available can you help me how to use it.

Below is my powershell command output coming in ansible result.

    "stdout_lines": [
        "",
        " Id ProcessName       CPU",
        " -- -----------       ---",
        "564 lsass        83.46875",
        "876 svchost     82.484375",
        "",
        ""
    ]

Expecting output like below format:

 "stdout_lines": 
    {
        "Id":  564,
        "ProcessName":  "lsass",
        "CPU":  83.46875
    },
    {
        "Id":  876,
        "ProcessName":  "svchost",
        "CPU":  82.484375
    }

so that I can fetch the id or process names like stdout_lines.ProcessName




Jordan Borean

unread,
Nov 22, 2019, 5:34:38 PM11/22/19
to Ansible Project
In your win_shell command add “| ConvertTo-Json” to the end. That will pipe the output into a json string which you can then use the from_json filter in Ansible to turn it into a dict.
Reply all
Reply to author
Forward
0 new messages