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
`
OOC, can you try single quotes? Just curious if that makes any difference…
./Alex
Single quotes makes no difference.
The issue fixed was casting in YAML:
varname: 1
not about templating, as YAML only sees a string:
varname “{{1}}”
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?