# Still in 2.1?: Nested values always cast to string

**URL:** <https://forum.ansible.com/t/still-in-2-1-nested-values-always-cast-to-string/21871>\
**Category:** Ansible Project\
**Created:** [June 28, 2016, 5:29am UTC](https://forum.ansible.com/t/still-in-2-1-nested-values-always-cast-to-string/21871 "2016-06-28T05:29:07Z")\
**Posts on this page:** 5\
**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 28, 2016, 5:29am UTC](https://forum.ansible.com/t/still-in-2-1-nested-values-always-cast-to-string/21871/1 "2016-06-28T05:29:07Z")

</div>

I thought one of the big improvements in 2.x was not blindly casting nested values to strings:

`  
vars:  
a\_var\_number: 200

tasks:

- mymodule:  
module\_args:  
a\_fixed\_number: 100  
a\_var\_number: “{{ a\_number }}”  
a\_var\_number\_with\_cast: “{{ a\_number | int }}”

`

Inside the module module\_args dict gets:

`

module = AnsibleModule(  
argument\_spec=dict(  
module\_args=dict(required=True, type=‘raw’)

),  
)

args= module.params[‘module\_args’]  
is\_num\_1 = isinstance(args[‘a\_fixed\_number’], int) # True  
is\_num\_2 = isinstance(args[‘a\_var\_number’], int) # False  
is\_num\_3 = isinstance(args[‘a\_var\_number\_with\_cast’], int) # False  
`

---

<div class="post-metadata">

**Author:** ![Alex\_Leonhardt](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Alex\_Leonhardt](https://forum.ansible.com/u/Alex_Leonhardt)\
**Post date:** [June 28, 2016, 5:54am UTC](https://forum.ansible.com/t/still-in-2-1-nested-values-always-cast-to-string/21871/2 "2016-06-28T05:54:44Z")

</div>

OOC, can you try single quotes? Just curious if that makes any difference…

./Alex

---

<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 28, 2016, 7:03am UTC](https://forum.ansible.com/t/still-in-2-1-nested-values-always-cast-to-string/21871/3 "2016-06-28T07:03:33Z")

</div>

Single quotes makes no difference.

---

<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 28, 2016, 2:30pm UTC](https://forum.ansible.com/t/still-in-2-1-nested-values-always-cast-to-string/21871/4 "2016-06-28T14:30:20Z")

</div>

​The issue fixed was casting in YAML:

varname: 1

not about templating, as YAML only sees a string:

varname “{{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 29, 2016, 8:03am UTC](https://forum.ansible.com/t/still-in-2-1-nested-values-always-cast-to-string/21871/5 "2016-06-29T08:03:20Z")

</div>

So if I understand Brain, that when passing dict (created from yaml) into a module or plugin, the python code must be aware of all the types of all the properties (flat or nested) and do the cast itself.

This is really fine for a module that consumes values itself. But in an example where the dict is just be converted to json and passed on to external service this will be pain.

Is this something just has-to-be due the internal design constraints, or might the yaml types be ever be retained in the dict passed to modules?
