1.2.2 variable reference syntax

Hello. I’m running Ansible 1.2.2 (seeing the below behavior on OSX and CentOS 6.4). My understanding is that in 1.2+, I can use {{ var }} syntax everywhere. In a role task I have this:

  • copy:
    src=“jdk-{{ oraclejdk_version }}-linux-amd64.rpm”
    dest=“{{ tmp_dir }}/jdk-{{ oraclejdk_version }}-linux-amd64.rpm”

The vars are specified in main.yml inside the same role. However, I get an error:

msg: Destination directory {{tmp_dir}} does not exist

If I change the “copy:” action to:

  • copy:
    src=“jdk-{{ oraclejdk_version }}-linux-amd64.rpm”
    dest=“${tmp_dir}/jdk-{{ oraclejdk_version }}-linux-amd64.rpm”

… the error goes away and all is well. Maybe this is a bug, okay, but I’m looking to find out if I’ve misunderstood the new syntax.

Thank you for any information.
-Scott

This is not how you do multiline copies. I’m not sure where you picked this up, but it looks like this if you want a line continuation.

  • copy: >
    src=“jdk-{{ oraclejdk_version }}-linux-amd64.rpm”
    dest=“{{ tmp_dir }}/jdk-{{ oraclejdk_version }}-linux-amd64.rpm”

Furthermore, the failure of your variable to evaluate is probably because the other variable didn’t substitute. Ansible probably couldn’t template something else on the line.

Thank you Michael. It was indeed the multi-line syntax error. Once I properly added the “copy: >” for multi-line, I was able to use the new variable syntax successfully.

It’s a little surprising that with incorrect multi-line syntax using the old variable syntax ${} masked the actual error. Regardless, I have a fix. Thanks for the fast reply.

This is not how you do multiline copies. I’m not sure where you picked this up, but it looks like this if you want a line continuation.

It was suggested in this thread:
https://groups.google.com/d/msg/ansible-project/EDXIk3WM7vk/Rx6mibjQvrcJ

I think some more documentation on this would be great.