Preserving list objects with Jinja2-style variables

Dear list,

please consider this playbook:

  - name: test playbook
    hosts: localhost
    gather_facts: no
    vars:
      mylist:
        - 1
        - 2
        - 3
      othervar: '{{mylist}}'
      escaped: \{{mylist}}
    tasks:
      - debug: msg='{{mylist.__class__}} {{othervar.__class__}} {{escaped.__class__}}'

The output is (list, unicode, unicode), which is rather unfortunate.

How do I preserve the type of a variable when interpolating like
above?

The same problem exists with booleans, and probably all other types:
Jinja2 templating returns strings, no matter what type you pass in.
This means that with legacy-style variables deprecated, and Jinja2
interpolating the inventory, there is no way in Ansible to preserve
the type of variables in the inventory.

Types in the playbooks don’t matter because all the necessary casting happens in the modules.