printing readable error message while in playbook debug mode

I get this error when I run my playbook (with debug strategy enabled):

`
TASK [Add authorized keys for developer user] **********************************************************************************************************************************************************************************************************************************
task path: /home/pi/Source/ansible/playbooks/post-preseeded-debian-install.yml:27
fatal: [tblack-win10]: FAILED! => {
“msg”: “The task includes an option with an undefined variable. The error was: ‘item’ is undefined\n\nThe error appears to have been in ‘/home/pi/Source/ansible/playbooks/post-preseeded-debian-install.yml’: line 27, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: "Add authorized keys for {{ preseeded_username }} user"\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - "{{ foo }}"\n\nexception type: <class ‘ansible.errors.AnsibleUndefinedVariable’>\nexception: ‘item’ is undefined”
}

`

It breaks into debug prompt, but when I print the error message there, it won’t do it pythonically, or even readable:

`
(debug) p result[‘msg’]
u’The task includes an option with an undefined variable. The error was: 'item' is undefined\n\nThe error appears to have been in '/home/pi/Source/ansible/playbooks/post-preseeded-debian-install.yml': line 27, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: “Add authorized keys for {{ preseeded_username }} user”\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - “{{ foo }}”\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'item' is undefined’

`

However, I can copy/paste the entire unicode string def, paste and print in a separate python interactive session variable, and it looks correct:

`
/home/tblack > python
Python 2.7.13 (default, Nov 24 2017, 17:33:09)
[GCC 6.3.0 20170516] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

m=u’The task includes an option with an undefined variable. The error was: 'item' is undefined\n\nThe error appears to have been in '/home/pi/Source/ansible/playbooks/post-preseeded-debian-install.yml': line 27, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: “Add authorized keys for {{ preseeded_username }} user”\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - “{{ foo }}”\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'item' is undefined’
type(m)
<type ‘unicode’>
print m
The task includes an option with an undefined variable. The error was: ‘item’ is undefined

The error appears to have been in ‘/home/pi/Source/ansible/playbooks/post-preseeded-debian-install.yml’: line 27, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

tasks:

  • name: “Add authorized keys for {{ preseeded_username }} user”
    ^ here
    We could be wrong, but this one looks like it might be an issue with
    missing quotes. Always quote template expression brackets when they
    start a value. For instance:

with_items:

  • {{ foo }}

Should be written as:

with_items:

  • “{{ foo }}”

exception type: <class ‘ansible.errors.AnsibleUndefinedVariable’>
exception: ‘item’ is undefined
`

How do I do same in the ansible debug prompt? Any other ideas on how to print this output in a READABLE fashion? Thanks.

So this is a strong indication that you have some errors in your code, so you need to show us the code in the file to figure it out.

My issue isn’t about whats wrong with my code, its a question about why ansible debugger wont print the newlines in a python string.