You can reduce the PowerShell to one line and, if you're only interested in
the output as a string, you can use *Out-String* command with the *-Width*
parameter
and a suitably large value:
win_shell: Get-NetAdapter | Where-Object {$_.Status -eq "up"} | Out-String -
Width 4096
results in:
Name InterfaceDescription ifIndex Status MacAddress LinkSpeed
---- -------------------- ------- ------ ---------- ---------
Ethernet vmxnet3 Ethernet Adapter 12 Up 00-50-56-00-00-00 10 Gbps
See
https://stackoverflow.com/questions/45978200/output-getting-truncated-using-winrm
for more info
You can also use *Select-Object* to just pick out the fields you're
interested in, e.g.:
win_shell: Get-NetAdapter | Select-Object Name,Status,MacAddress,LinkSpeed |
Where-Object {$_.Status -eq "up"} | Out-String -Width 4096
On Monday, 11 February 2019 16:28:22 UTC, yarecki wr wrote:
>
> Strange but I run the playbook again and it actually gives me some output.
> Many thanks for the explanation regarding the pipe sign. Makes things more
> clear now.
> Problem is in stdout_lines, this doesn't display the same info that it
> would display when it was run directly on the Windows box. It cuts off last
> two columns which are my MACaddress and LinkSpeed.
>
> On Sunday, February 10, 2019 at 11:13:09 AM UTC+1, Igor Turovsky wrote:
>>
>> Pipe character after win_shell indicates that Powershell code should be
>> treated as multi-lined.
>> What error did you get?
>>
>> пт, 8 февр. 2019 г. в 20:35, yarecki wr <[email protected]>:
>>
>>> I'm testing Ansible to see if I can successfully control various aspects
>>> of Windows management. I'm getting stuck on using variables and
>>> conditionals and can't interpret the error information that comes back.
>>>
>>> I tried to run a playbook against a test machine where I used some
>>> conditionals and loop statements as in the example below.
>>>
>>> ---
>>> hosts: myhost.domain.local
>>> tasks:
>>> - name: get all connected network adapters
>>> win_shell: |
>>> $adapters = @(Get-NetAdapter)
>>> foreach($item in $adapters){if($item.status -eq "Up"){$item}}
>>>
>>> So above I first assign a variable to a list of all network adapters
>>> that can be found on my system and then I wan't to extract only those that
>>> are actually up and connected. I'm getting some cryptic response where I
>>> can find syntax errors so the above code must be somehow misinterpreted.
>>> I'll probably would want to expand this code to gather more details but
>>> since I'm stuck just with the basics I can't move forward. BTW not sure why
>>> the | pipe character after win_shell. Just seen it in a couple of simple
>>> examples on the web. Couldn't find any good examples and there was no
>>> answer in other forum.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Ansible Project" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/3b463339-bcf9-4dfc-aed3-669f9c060ee2%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/ansible-project/3b463339-bcf9-4dfc-aed3-669f9c060ee2%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/819087f5-eeda-4d8c-ac5d-20cb974e2530%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.