# printing readable error message while in playbook debug mode

**URL:** <https://forum.ansible.com/t/printing-readable-error-message-while-in-playbook-debug-mode/26690>\
**Category:** Ansible Project\
**Created:** [February 8, 2018, 8:18pm UTC](https://forum.ansible.com/t/printing-readable-error-message-while-in-playbook-debug-mode/26690 "2018-02-08T20:18:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Black](https://avatars.discourse-cdn.com/v4/letter/t/bcef8e/32.png) [@Tim\_Black](https://forum.ansible.com/u/Tim_Black)\
**Post date:** [February 8, 2018, 8:18pm UTC](https://forum.ansible.com/t/printing-readable-error-message-while-in-playbook-debug-mode/26690/1 "2018-02-08T20:18:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 8, 2018, 8:30pm UTC](https://forum.ansible.com/t/printing-readable-error-message-while-in-playbook-debug-mode/26690/2 "2018-02-08T20:30:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tim\_Black](https://avatars.discourse-cdn.com/v4/letter/t/bcef8e/32.png) [@Tim\_Black](https://forum.ansible.com/u/Tim_Black)\
**Post date:** [February 9, 2018, 5:52am UTC](https://forum.ansible.com/t/printing-readable-error-message-while-in-playbook-debug-mode/26690/3 "2018-02-09T05:52:44Z")

</div>

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.
