Retrieve a value from a dictionary in stderr

Skip to first unread message

Glenn Robinson

unread,
Mar 15, 2021, 6:13:45 AM3/15/21
to Ansible Project
I'm using a module which returns some information in the module's register stderr variable when the module encounters an issue.

Using  - debug: var=sql_delete.stderr returns:

ok: [ibmi01] => {
    "sql_delete.stderr": {
        "ccsid": "1146",
        "curuser": "GROBINSO",
        "dftccsid": "1146",
        "error": "*** error DELETE FROM ANSIBLIB.QCUSTCDT WHERE CDTLMT < 9999.00",
        "jobipc": "*na",
        "jobipcskey": "FFFFFFFF",
        "jobname": "QSQSRVR",
        "jobnbr": "002988",
        "jobuser": "QUSER",
        "paseccsid": "0",
        "syslibl": "QSYS QSYS2 QHLPSYS QUSRSYS",
        "usrlibl": "QGPL QTEMP",
        "version": "XML Toolkit 1.9.2",
        "xmlhint": "02000:100:Row not found for DELETE.",
        "xmlhint1": "02000:100:Row not found for DELETE."
    }
}

I want to retrieve the value in the xmlhint item.

When i try and access that value by using:

sql_delete.stderr.xmlhint 

I get a variable not found error.

I've tried from_json, dict2items and dict2list but can't seem to reference the xmlhint, or any other key values, within stderr.

How do I reference the xmlhint value in sql_delete.stderr?

Vladimir Botka

unread,
Mar 15, 2021, 6:56:18 AM3/15/21
to Glenn Robinson, ansible...@googlegroups.com
What type is the attribute *stderr*? Try

- debug:
msg: "{{ sql_delete.stderr|type_debug }}"

If the type is string convert it to dictionary first, e.g

- debug:
msg: "{{ _stderr.xmlhint }}"
vars:
_stderr: "{{ sql_delete.stderr|from_yaml }}"


--
Vladimir Botka

Glenn Robinson

unread,
Mar 15, 2021, 7:08:59 AM3/15/21
to Ansible Project
Attribute type returns: 

   "msg": "AnsibleUnsafeText"


- debug:
      msg: "{{ sql_delete }}"

returns:

ok: [ibmi01] => {
    "msg": {
        "changed": false,
        "delta": "0:00:00.325885",
        "end": "2021-03-14 23:05:33.098261",
        "failed": true,
        "msg": "non-zero return code:255",
        "rc": 255,
        "sql": "DELETE FROM ANSIBLIB.QCUSTCDT WHERE CDTLMT < 9999.00",
        "start": "2021-03-14 23:05:32.772376",
        "stderr": "{'error': '*** error DELETE FROM ANSIBLIB.QCUSTCDT WHERE CDTLMT < 9999.00', 'version': 'XML Toolkit 1.9.2', 'xmlhint': '02000:100:Row not found for DELETE.', 'xmlhint1': '02000:100:Row not found for DELETE.', 'jobipc': '*na', 'jobipcskey': 'FFFFFFFF', 'jobname': 'QSQSRVR', 'jobuser': 'QUSER', 'jobnbr': '007433', 'curuser': 'GROBINSO', 'ccsid': '1146', 'dftccsid': '1146', 'paseccsid': '0', 'syslibl': 'QSYS QSYS2 QHLPSYS QUSRSYS', 'usrlibl': 'QGPL QTEMP'}",
        "stderr_lines": [
            "{'error': '*** error DELETE FROM ANSIBLIB.QCUSTCDT WHERE CDTLMT < 9999.00', 'version': 'XML Toolkit 1.9.2', 'xmlhint': '02000:100:Row not found for DELETE.', 'xmlhint1': '02000:100:Row not found for DELETE.', 'jobipc': '*na', 'jobipcskey': 'FFFFFFFF', 'jobname': 'QSQSRVR', 'jobuser': 'QUSER', 'jobnbr': '007433', 'curuser': 'GROBINSO', 'ccsid': '1146', 'dftccsid': '1146', 'paseccsid': '0', 'syslibl': 'QSYS QSYS2 QHLPSYS QUSRSYS', 'usrlibl': 'QGPL QTEMP'}"
        ],
        "stdout": "",
        "stdout_lines": []
    }
}

Reply all
Reply to author
Forward
0 new messages