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

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

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5475E705.6010406%40mvua.de.
For more options, visit https://groups.google.com/d/optout.

Reply via email to