Referencing complex data type variables

Hi,

With Jinja2 varibles it is not possible to do:

  complex_var:
    - name: "foo"
      size: 12
    - name: "bar"
      size: 33
  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

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

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 :slight_smile:

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

Somewhere in advanced playbooks makes sense.