# yaml structures passed to roles that to\_json cannot use integers

**URL:** <https://forum.ansible.com/t/yaml-structures-passed-to-roles-that-to-json-cannot-use-integers/18370>\
**Category:** Ansible Project\
**Created:** [June 1, 2015, 4:30pm UTC](https://forum.ansible.com/t/yaml-structures-passed-to-roles-that-to-json-cannot-use-integers/18370 "2015-06-01T16:30:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [June 1, 2015, 4:30pm UTC](https://forum.ansible.com/t/yaml-structures-passed-to-roles-that-to-json-cannot-use-integers/18370/1 "2015-06-01T16:30:54Z")

</div>

I just got hit with [https://github.com/ansible/ansible/issues/9362](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?

---

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [June 22, 2015, 5:58am UTC](https://forum.ansible.com/t/yaml-structures-passed-to-roles-that-to-json-cannot-use-integers/18370/2 "2015-06-22T05:58:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 26, 2015, 3:39am UTC](https://forum.ansible.com/t/yaml-structures-passed-to-roles-that-to-json-cannot-use-integers/18370/3 "2015-06-26T03:39:44Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![David\_Birdsong](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@David\_Birdsong](https://forum.ansible.com/u/David_Birdsong)\
**Post date:** [July 10, 2015, 1:40am UTC](https://forum.ansible.com/t/yaml-structures-passed-to-roles-that-to-json-cannot-use-integers/18370/4 "2015-07-10T01:40:54Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [July 11, 2015, 2:24am UTC](https://forum.ansible.com/t/yaml-structures-passed-to-roles-that-to-json-cannot-use-integers/18370/5 "2015-07-11T02:24:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 11, 2015, 2:27am UTC](https://forum.ansible.com/t/yaml-structures-passed-to-roles-that-to-json-cannot-use-integers/18370/6 "2015-07-11T02:27:48Z")

</div>

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.
