question on variable references in 1.4

Hello,

i’d like to do something like with ansible 1.4 :

mylist:

  • key1: val1
    key2: “{{ key1 }}” # val1

  • key1: val3
    key2: “{{ key1 }}” # val3

I tried different things (like key2: “{{ mylist[0].key1 }}”) but cannot seem to find a way to do it.

I agree this is a bit contrived but I was wondering if I am missing something.

can someone point me to the documentation where the zoo of possible references is explained ?

thank you

there is a yamllism for just pure reference (no concat or subsitution)

mylist:

  • key1 : &key1reuse val1
    key2: *key1reuse

Thank you that will do the trick in my case.

for reference, the message from Michael on the new variable references in 1.4 is
https://groups.google.com/forum/#!searchin/ansible-project/variable$20in$201.4/ansible-project/GzT3Mvukb1E/yMw8uorwoYwJ

Right, you can’t reference a variable inside another, but “{{ foo }}” references structured variables fine in 1.4 otherwise.

(I’m not fond of YAML anchors, personally)

anyway yaml anchors don’t do concatenation as Brian mentionned.

In my case let’s say i want :

mylist:

  • key1: a
    key2: b
    key3: a-b

  • key1: c
    key2: d
    key3: c-d

what would be the best way to do that if i don’t want to carry “{{ item.key1 }}-{{ item.key2 }}” all over the place in the tasks ?

I have the case where key1 = application name, key2 = git sha of the application version
and i want to install the versioned application in key1-key2 and make reference to that “install_dir” in many places.

thanks

" “{{ item.key1 }}-{{ item.key2 }}”"

Ansible variables bind late, so if you want to define a variable like so:

vars:
item_k1k2: “{{ item.key1 }} - {{ item.key2 }}”

It should work fine.

Though I’d pick a better variable name than what I picked above :slight_smile: