Redirect verbose stream to stdout

Viewed 275

I would like to enrich my Ansible logs with info from the Verbose stream. Using Ansible 2.9.25 with Powershell 5.1

So I am trying to tie verbose output to standard out:

- win_shell: Expand-Archive jinja2_files.zip -DestinationPath . -Force -Verbose 4>&1
  args:
    chdir: e:\temp\Unzip

Expand-Archive is one of the Powershell cmdlet that supports -Verbose but the behavior is exactly the same with other cmdlets.

No matter what I do my stdout is blank in the task output log:

"stdout": "",

I could redirect to a temp file, read it and discard it but hopefully there is a better way.

Confirmed Ansible is able to write to both sdout and sderr.

1 Answers

You can use expressions to capture Verbose and Standard output into variables.

Save both Output and Verbose into single variable

$VerboseAndOutput = $(Expand-Archive -Path "C:\2019_OfficeContent_Symbols.zip" -Verbose) 4>&1

Save Output and Verbose into separate variables

$VerboseOnly = $($OutputOnly= .{
    Expand-Archive -Path "C:\2019_OfficeContent_Symbols.zip" -Verbose
}) 4>&1

So, something like the following should work for you:

- win_shell: $(Expand-Archive jinja2_files.zip -DestinationPath . -Force -Verbose) 4>&1
  args:
    chdir: e:\temp\Unzip

If you also want to capture warnings:

- win_shell: $(Expand-Archive jinja2_files.zip -DestinationPath . -Force -Verbose) 4>&13>&1
  args:
    chdir: e:\temp\Unzip
Related