In python script I’m reading data from “Incident” table(MSSQL DB) and printing it. When script is attempting to print the table’s data after fetching it from the table, the job is getting hard stopped without executing the complete playbook with errors.
error: Failed to JSON parse a line from worker stream. ErrorInvalid \escape: line 1 column 32804(char 32803) line with invalid JSON data: …
I’m facing the same issue with couple of other usecases on my newly deployed awx instance, but when I’m executing the same playbook on some other awx instance it’s working there.
Not sure what configurations I’ve missed and how to fix it. It seems like it has something to do with the char limit or the length of output or the data which is be processed.
It looks like the issue is really related to how AWX handles the script output. The error Failed to JSON parse a line from worker stream. ErrorInvalid \escape most often occurs when stdout contains characters that Ansible cannot correctly serialize to JSON, such as unhandled backslashes , quotes, or very long lines.
What you can try:
If you are simply doing print(data) in your Python script, try using json.dumps(data, ensure_ascii=False) to avoid incorrect escaping.
Also, pay attention to the output length. In some cases, AWX crashes if too much data is written to the log. In such cases, it is better to save the script output to a temporary file, and only print a short message about success in the playbook.
If everything works on another instance, it is possible that they have different environment settings - Python version, logger configuration, or Ansible environment variables.
If you find the exact reason, it will be interesting to know what the problem was. Good luck with debugging!