# Referencing complex data type variables

**URL:** <https://forum.ansible.com/t/referencing-complex-data-type-variables/13048>\
**Category:** Ansible Project\
**Created:** [July 1, 2013, 7:13pm UTC](https://forum.ansible.com/t/referencing-complex-data-type-variables/13048 "2013-07-01T19:13:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GW1](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@GW1](https://forum.ansible.com/u/GW1)\
**Post date:** [July 1, 2013, 7:13pm UTC](https://forum.ansible.com/t/referencing-complex-data-type-variables/13048/1 "2013-07-01T19:13:35Z")

</div>

```auto
Hi,

```

```auto

```

```auto
With Jinja2 varibles it is not possible to do:

```

```auto

```

```auto
  complex_var:

```

```auto
    - name: "foo"

```

```auto
      size: 12

```

```auto
    - name: "bar"

```

```auto
      size: 33

```

```auto
  another_var: $complex_var

```

And than use `another_var` like a complex variable, because everything gets casted to a string when it goes through Jinja2.

Is there a long-term plan on dropping old-style variables?

If yes, to me it seems that it could be possible to use YAML anchors and references to solve such simple use cases:

another\_var: \*complex\_var

[https://en.wikipedia.org/wiki/YAML#References](https://en.wikipedia.org/wiki/YAML#References)

Or custom data types:

another\_var: !ref complex\_var

Or something similar that would result in valid YAML without introducing complex new concepts.

Greetings,  
gw

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 1, 2013, 7:16pm UTC](https://forum.ansible.com/t/referencing-complex-data-type-variables/13048/2 "2013-07-01T19:16:35Z")

</div>

There is no immediate plan to drop old style references, but we have generally tried to not talk about them.

It may be worthwhile mentioning they are useful in this kind of use case, however.

I find YAML anchors pretty hideous so we don’t really encourage that, as well as the same for YAML data types. Most people don’t understand them and I don’t really want them to have to if I can help it 🙂

---

<div class="post-metadata">

**Author:** ![kahlil.hodgson](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@kahlil.hodgson](https://forum.ansible.com/u/kahlil.hodgson)\
**Post date:** [July 1, 2013, 10:31pm UTC](https://forum.ansible.com/t/referencing-complex-data-type-variables/13048/3 "2013-07-01T22:31:14Z")

</div>

I use the old style references quite a bit in my inventory vars files to denormalize data in order to avoid complex lookups in playbooks and templates. The $ syntax is definitely cleaner than anchors and I’d hate to see it go. It think it would be worthwhile documenting this, though I’m not sure where we would put it. Perhaps under Advanced Playbooks in a new section after the “Variable File Separation”?

K

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 1, 2013, 10:36pm UTC](https://forum.ansible.com/t/referencing-complex-data-type-variables/13048/4 "2013-07-01T22:36:17Z")

</div>

Somewhere in advanced playbooks makes sense.
