Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional exceptions attached to stderr in script module #76237

Open
1 task done
dozhang opened this issue Nov 8, 2021 · 2 comments
Open
1 task done

Additional exceptions attached to stderr in script module #76237

dozhang opened this issue Nov 8, 2021 · 2 comments
Assignees
Labels
affects_2.10 This issue/PR affects Ansible v2.10 affects_2.16 affects_2.17 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@dozhang
Copy link

dozhang commented Nov 8, 2021

Summary

With remote host windows, when using script module if the script write some content to stderr, then additional exceptions will be attached to the content in result.

Issue Type

Bug Report

Component Name

script

Ansible Version

$ ansible --version
ansible 2.10.6
  config file = None
  configured module search path = ['/Users/xxxxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/xxxxx/Library/Python/3.7/lib/python/site-packages/ansible
  executable location = /Users/xxxxx/Library/Python/3.7/bin/ansible
  python version = 3.7.9 (v3.7.9:13c94747c7, Aug 15 2020, 01:31:08) [Clang 6.0 (clang-600.0.57)]

Configuration

$ ansible-config dump --only-changed
empty

OS / Environment

Control node: MacOS 10.15.7
Manged node: Windows 2019

Steps to Reproduce

Playbook:

---
- name: test script module
  hosts: all
  tasks:
    - name: test local script
      script: show_warning.py
      args:
        executable: 'path\to\python.exe'

show_warning.py

import sys
print("test content", file=sys.stderr)

Expected Results

"stderr" should only contain "test content" in result.

Actual Results

TASK [test local script] *********************************************************************************************************************************************
task path: /Users/xxxx/Temp/playbooks/HelloWorld.yaml:8
<xx.xx.xx.xx> ESTABLISH WINRM CONNECTION FOR USER: xxxxxx on PORT 5986 TO 10.31.2.209
EXEC (via pipeline wrapper)
<xx.xx.xx.xx> PUT "/Users/xxxx/Temp/playbooks/show_warning.py" TO "C:\Users\xxxxxx\AppData\Local\Temp\ansible-tmp-1636358586.975513-5380-121049279246891\show_warning.py"
EXEC (via pipeline wrapper)
EXEC (via pipeline wrapper)
changed: [xx.xx.xx.xx] => {
    "changed": true,
    "rc": 0,
    "stderr": "test contentAt line:1 char:1+ &  C:\\Users\\xxxxxx\\cilib\\Scripts\\python.exe C:\\Users\\Administr ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (test content:String) [], RemoteException    + FullyQualifiedErrorId : NativeCommandErrorScriptStackTrace:at <ScriptBlock>, <No file>: line 1",
    "stderr_lines": [
        "test contentAt line:1 char:1+ &  C:\\Users\\Administrator\\cilib\\Scripts\\python.exe C:\\Users\\Administr ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (test content:String) [], RemoteException    + FullyQualifiedErrorId : NativeCommandErrorScriptStackTrace:at <ScriptBlock>, <No file>: line 1"
    ],
    "stdout": "",
    "stdout_lines": []
}

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot
Copy link
Contributor

ansibot commented Nov 8, 2021

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Nov 8, 2021
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Nov 9, 2021
@jborean93
Copy link
Contributor

The reason why this happens is because scripts are run like this in Ansible

$ps = [PowerShell]::Create()
[void]$ps.AddScript('executable script_path')
$output = $ps.Invoke()

$output -join "`r`n"
# Not actually the code but essentially error records are written to stderr
$host.UI.WriteErrorLine($ps.Streams.Error)

In this case the script is still writing the value to stderr which is sent back to the controller but Ansible is processing each error record as the output of stderr from PowerShell becomes an error record automatically. Looks like we are going to need special handling for all this when the executable is set to only output was was on stdout and stderr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.10 This issue/PR affects Ansible v2.10 affects_2.16 affects_2.17 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants