ansible-collections / ibm_zos_core

Red Hat Ansible Certified Content for IBM Z
75 stars 44 forks source link

[Bug] [ansible] SyntaxError: Non-UTF-8 code starting with '\\x88' in file <stdin> on line 1, but no encoding declared #1468

Closed gngrossi closed 2 months ago

gngrossi commented 2 months ago

Is there an existing issue for this?

Bug description

Issue running an ansible command for the ping module. Able to run a playbook for it.

IBM z/OS Ansible core Version

v1.9.0

IBM Z Open Automation Utilities

v1.2.5 (default)

IBM Enterprise Python

v3.12.x

ansible-version

v2.16.x (default)

z/OS version

v2.5 (default)

Ansible module

No response

Playbook verbosity output.

bash-4.4$ ansible -m ping all mvs-sysd | FAILED! => { "changed": false, "module_stderr": "SyntaxError: Non-UTF-8 code starting with '\x88' in file on line 1, but no encoding declared; see https://peps.python.org/pep-0263/ for details\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1 }

playbook runs successfully.


Ansible configuration.

defaults]
forks = 25
inventory = ~/playbooks/inventory.yml
host_key_checking = false
remote_port = 2222
timeout = 15
#deprecation_warnings=false

[ssh_connection]
pipelining = true

Contents of the inventory

MA1:
  hosts:
    mvs-sysd:
  vars:
    ansible_user: "@02858"

Contents of group_vars or host_vars

ZOAU_HOME:        /hewitt/zopentools/zoau1258
#ZOAU_HOME:        /hewitt/zopentools/zoau1310
#PYZ_HOME:         /hewitt/zopentools/python311/usr/lpp/IBM/cyp/v3r11/pyz
PYZ_HOME:         /hewitt/zopentools/python312/usr/lpp/IBM/cyp/v3r12/pyz

ansible_python_interpreter: "{{PYZ_HOME}}/bin/python3"

environment_vars:
  LIBPATH:        "{{ZOAU_HOME}}/lib:{{PYZ_HOME}}/lib:/lib:/usr/lib:."
  PATH:           "{{ZOAU_HOME}}/bin:{{PYZ_HOME}}/bin:/bin:/usr/sbin:."

  PYTHONSTDINENCODING: cp1047

# not compatible with pip installing the zoau package
# PYTHONPATH:     "{{ZOAU_HOME}}/lib"

# works without it
# LANG: C

  _BPXK_AUTOCVT:  ON
  _CEE_RUNOPTS:   "FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)"
  _TAG_REDIR_IN:  txt
  _TAG_REDIR_OUT: txt
  _TAG_REDIR_ERR: txt
ketankelkar commented 2 months ago

It looks like you're using the ad-hoc ansible command (docs). That one is tricky to use with z/OS targets because there isn't a clean way to pass in environment variables (which are very helpful in dealing with UTF8/EBCDIC encoding). For this reason, we generally don't recommend the ad-hoc command route. Your playbook above seems alright to me, and if I understood correctly, it was working for you.

(Just an FYI): The recommended environment vars (below) assist with auto-conversion/auto-tagging files. Ansible operates strictly in the UTF-8 encoding space, while z/OS does some of both UTF-8 and EBCDIC.

  _BPXK_AUTOCVT:  ON
  _CEE_RUNOPTS:   "FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)"
  _TAG_REDIR_IN:  txt
  _TAG_REDIR_OUT: txt
  _TAG_REDIR_ERR: txt

(to the point): I found two ways to enable the command ansible -m ping all. They're both sort of hack-y / undesirable:

You may eventually run into the following error when working with the zos_ping module:

"module_stdout": "< path_to_temp_file >/AnsiballZ_zos_ping.rexx 1: FSUM7332 syntax error: got (, expecting Newline\r\n",

If that happens, set the scp_extra_args parameter like so either in ansible.cfg or the inventory (or group_vars/host_vars).

Let me know if this helps or if there's anything I didn't answer/address

gngrossi commented 2 months ago

@ketankelkar Success...much appreciated.

bash-4.4$ ansible -m ping all mvs-sysj | SUCCESS => { "changed": false, "ping": "pong" }

I opted for option1... I tried adding to vars: so it could be shared for every host but it doesn't work from there like ansible_user.

For ansible ad-hoc commands, ansible_python_interpreter is defined in the inventory file. For ansible-playbook commands, ansible_python_interpreter is defined in group_vars.

MA1: hosts: mvs-sysj: ansible_python_interpreter: "env PYTHONSTDINENCODING=cp1047 ...." vars: ansible_user: "@02858"

closing...thanks