yaml structures passed to roles that to_json cannot use integers

I just got hit with https://github.com/ansible/ansible/issues/9362, where in the following ‘instances’ is a string when the role uses to_json to pass the data to marathon:

`
vars:
vi_instances: “{{instances | default(2)}}”

roles:

  • role: marathon_app
    marathon_app:
    id: /svc/auth
    cpus: 0.5
    mem: 64.0
    instances: “{{vi_instances | int}}”
    `

Does anybody know a workaround to this?

I’m still hitting a wall on this. Any ideas anybody?

A fix for this was merged to current devel, I'm not sure we can
backport it to older versions as the templating code involved was very
convoluted (much simpler in new version).

A fix for this was merged to current devel, I’m not sure we can
backport it to older versions as the templating code involved was very
convoluted (much simpler in new version).

any news on this front?

i’m trying to share data directly between ansible and consul by inheriting data from upper level variables files and i can’t get integers to render to json as integers.

I have to say this is in my top 5 biggest ansible yak shavings. So many times I just need to pass configuration directly to a role which would to_json or to_yaml it. But I cannot because of this bug. Hence I need to parse out every little variable all the way down the structure ensuring that ints or floats get converted.

Something that would be simple and elegant turns into a turd.

Sorry to hear,

We hope to release next month, hopefully that will fix this issue.
Variable handling was one major headache of the old codebase, part of
the reason we rewrote the core.