Ansible win_shell printing wrong output

244 views Asked by At

Ansible win_shell/win_command prints logo output instead of actual output of the command:

- name: get Ps1 files
      win_shell: get-ChildItem -path $testFolder -Filter *.ps1 -Recurse -File -Name -Depth 0
      register: ps1_files
      args:
        executable: powershell

Should print a list of *.ps1 folders but instead prints wrong output (command works when running directly on powershell on the server):

"msg": {
2022-12-22T02:30:46.455812-0500 info:         "changed": true, 
2022-12-22T02:30:46.455867-0500 info:         "cmd": "get-ChildItem -path $realProcessesFolder -Filter *.ps1 -Recurse -File -Name -Depth 0", 
2022-12-22T02:30:46.455917-0500 info:         "delta": "0:00:00.954839", 
2022-12-22T02:30:46.455969-0500 info:         "end": "2022-12-22 07:30:46.385668", 
2022-12-22T02:30:46.456017-0500 info:         "failed": false, 
2022-12-22T02:30:46.456065-0500 info:         "rc": 0, 
2022-12-22T02:30:46.456115-0500 info:         "start": "2022-12-22 07:30:45.430828", 
2022-12-22T02:30:46.456165-0500 info:         "stderr": "", 
2022-12-22T02:30:46.456237-0500 info:         "stderr_lines": [], 
2022-12-22T02:30:46.456289-0500 info:         "stdout": "\r\n\r\nComputerName  : SL143312\r\nBuilddate     : 2019-Aug-26 13:43:8\r\nProfile       : Standard Application Server\r\nOS            : Windows Server 2016 Standard Edition\r\nMachineType   : VMware Virtual Platform\r\nModel         : VMware, Inc.\r\nServerAppCode : TVP0\r\n\r\n\r\n\r\n", 
2022-12-22T02:30:46.456343-0500 info:         "stdout_lines": [
2022-12-22T02:30:46.456393-0500 info:             "", 
2022-12-22T02:30:46.456445-0500 info:             "", 
2022-12-22T02:30:46.456504-0500 info:             "ComputerName  : SL143312", 
2022-12-22T02:30:46.456556-0500 info:             "Builddate     : 2019-Aug-26 13:43:8", 
2022-12-22T02:30:46.456615-0500 info:             "Profile       : Standard Application Server", 
2022-12-22T02:30:46.456663-0500 info:             "OS            : Windows Server 2016 Standard Edition", 
2022-12-22T02:30:46.456718-0500 info:             "MachineType   : VMware Virtual Platform", 
2022-12-22T02:30:46.456767-0500 info:             "Model         : VMware, Inc.", 
2022-12-22T02:30:46.456816-0500 info:             "ServerAppCode : TT00", 
2022-12-22T02:30:46.456866-0500 info:             "", 
2022-12-22T02:30:46.456916-0500 info:             "", 
2022-12-22T02:30:46.456977-0500 info:             ""
2022-12-22T02:30:46.457027-0500 info:         ]
2022-12-22T02:30:46.457079-0500 info:     }

This looks to me more like a logo. I have used also the win_command module with nologo and came up with same result:

win_command: powershell -noninteractive -nologo -command  "get-ChildItem -path $env:realProcessesFolder -Filter *.ps1 -Recurse -File -Name -Depth 0" 

It would be great if you would have any suggestions. Many thanks!

0

There are 0 answers