printing readable error message while in playbook debug mode

55 views
Skip to first unread message

Tim Black

unread,
Feb 8, 2018, 3:18:04 PM2/8/18
to Ansible Project
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.

Kai Stian Olstad

unread,
Feb 8, 2018, 3:31:11 PM2/8/18
to ansible...@googlegroups.com
On Thursday, 8 February 2018 21.18.03 CET Tim Black wrote:
> 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.

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.


--
Kai Stian Olstad

Tim Black

unread,
Feb 9, 2018, 12:52:56 AM2/9/18
to ansible...@googlegroups.com
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.

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/VEkV22Mf2ac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1534323.axfGH9Ad8Q%40x1.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages