Template fails with diff if dest=directory w/o trailing / - shall provide better error message

48 views
Skip to first unread message

Jakub Holy

unread,
Mar 7, 2014, 3:47:00 AM3/7/14
to ansible...@googlegroups.com
The following will fail in Ansible 1.5 but only when run with --diff:

---
#  broken_template_diff.yml
- hosts: all
  gather_facts: False
  sudo: False
  tasks:
  - template: src=mytemplate.txt dest=/tmp   # BROKEN
  #- template: src=mytemplate.txt dest=/tmp/ # WORKING

When run with

ansible-playbook -vi local broken_template_diff.yml --diff # I could also add -C here

this will fail with

fatal: [localhost] => failed to parse: Traceback (most recent call last):
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1394180980.94-199465317382554/slurp", line 1144, in <module>
    main()
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1394180980.94-199465317382554/slurp", line 67, in main
    data = base64.b64encode(file(source).read())
IOError: [Errno 21] Is a directory: '/tmp'

When run without --diff or after adding the trailing /, it will work.

In this particular case it actually tells me what is the problem but when I run it with my slightly different production configuration and against CentOS 5.9 (with an older Python) it is even worse because I get

fatal: [10.0.2.2] => failed to parse: SUDO-SUCCESS-advisvcbctshnxbofoyvoppteorclbaf
Traceback (most recent call last):
  File "/tmp/ansible-tmp-1394181207.71-130165043237097/slurp", line 1144, in ?
    main()
  File "/tmp/ansible-tmp-1394181207.71-130165043237097/slurp", line 67, in main
    data = base64.b64encode(file(source).read())
IOError: [Errno 21] Is a directory

- notice it does not tell me the name of the path that is directory even though template+diff does not expect that. So it might seems that it is the source that is a directory, which is pretty confusing.

SUMMARY

  1. --diff should not fail when there is missing the trailing slash in dest=/path/to/directory (since non-diff does not fail either) or it should at least provide much better error message
  2. Under CentOS 5.9 (<=> Python 2.4) the error message does not contain the directory's name, which makes it very confusing

Should I open an issue for #1?

Thank you!

Jakub Holy

unread,
Mar 13, 2014, 10:49:18 AM3/13/14
to ansible...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages