Different lookup behavior (in listify_lookup_plugin_terms) between Ansible 1.7.2 and Ansible 1.8

109 views
Skip to first unread message

David Fritzsche

unread,
Nov 26, 2014, 12:12:05 PM11/26/14
to ansible...@googlegroups.com
Hi all,

thanks for all the hard work to make the new Ansible version possible.

I tested the new version with my current setup of playbooks and I got the
strange behavior that some file content I lookup with lookup('file', 'path')
and then copy it to a remote host did not got copied correctly with Ansible
1.8 anymore. The reason is the new fail_on_undefined argument (and its default
value of True) of the utils.listify_lookup_plugin_terms() function. Since path
is not a valid variable an exception is raised which is then silenced in
template.lookup() and then an empty file is copied to the remote host. This
happens even though 'path' is the (relative) path to an existing file.

In general I found it quite surprising that Ansible tries to template-expand
the string 'path' by feeding '{{path}}' into the template.template() function
(seemingly in both Ansible 1.7.2 and Ansible 1.8).

Moreover, the silencing of exceptions in template.lookup() took me quite some
time to find the source of the problems. The observed behavior was just that
empty files were transferred - no error was reported!


My example can be fixed to work for both versions for now by using
lookup('file', './path'). Somehow Jinja2 expands '{{./path}}' to './path'.


The following test example shows the behavior difference:

Assume we have a simple playbook like the following:

########## lookup.yml ##########
---
- hosts: somehost
tasks:

- copy:
content: "{{ lookup('file', 'foo') }}"
dest: "/tmp/foo"
########## lookup.yml ##########

Now run the following commands:

$ echo "bazum" > foo
$ ansible-playbook lookup.yml
$ ssh somehost "ls -l /tmp/foo;cat /tmp/foo;echo"

the output with Ansible 1.7.2 is (as I would expect):

####################
-rw-r--r-- 1 root wheel 5 Nov 26 13:49 /tmp/foo
bazum
####################

With Ansible 1.8 the lookup fails (silently!!) and an empty file is
transferred to the remote host, i.e., the output of the commands above ends with

####################
-rw-r--r-- 1 root wheel 0 Nov 26 13:51 /tmp/foo

####################

Brian Coca

unread,
Nov 26, 2014, 2:35:50 PM11/26/14
to ansible...@googlegroups.com
for those that find this on google, this issues is more detailed in:
https://github.com/ansible/ansible/issues/9637

--
Brian Coca
Reply all
Reply to author
Forward
0 new messages