Passing long values to Ansible variable file (all.yml) without quotes

ANSIBLE VERSION

2.7.5

SUMMARY

I have the below list of variables defined in all.yml

abc: 3V4L-CA6S-UHJ8
xyz: 06342107

MC_INI_VAR: " {{abc}} {{xyz}}"

This has been invoked in playbook using the below rule

name : Starting generation process
become: yes
become_user: centos
shell : java -jar run.jar {{MC_INI_VAR}}
register: out

  • debug: var=o

At the remote machine the transformed command was

java -jar run.jar 3V4L-CA6S-UHJ8 1688647

If I just change the variable in all.yml to

abc: 3V4L-CA6S-UHJ8
xyz: “06342107”

At the remote machine the transformed command was

java -jar run.jar 3V4L-CA6S-UHJ8 06342107

My problem is that if xyz=06342108; it is sent correctly without quotes

Also, this value (in all.yml) is getting populated from another script which does not add quotes. I am reading about issues of handling long int in ansible variable and I need to understand on how can I fix this issue.

I do not wish to send this in quotes and and i have tried solutions like

MC_INI_VAR: " {{abc | string}} {{xyz}}" but it ain’t worked

Please suggest on how can I pass such values as string without quotes or if I can type cast those in playbook itself.

Without quotes, xyz: 06342107 looks like an octal number to yaml
(leading 0) and that is how it will be interpreted, adding the quotes
force it to be a string.

You cannot type cast it after the fact, because conversion already
occurred, the k=v notation doesn't do number conversion that is why
that works directly.

Thanks Brian!

My problem is that these values are generated programatically. In such cases I have to generate these with quotes in the values. Isn’t there any other way to treat the values with leading 0’s diffferently?

there is !!str yamlism to force always to interpret as strings

xyz: !!str 06342107