Ansible Strange Type Conversion When Using Inventory Files vs. Setting Vars on command line

Viewed 27

When using Ansible, I've observed some strange behavior that I can't understand. Hopefully someone on here can help.

If I define a playbook like so:

---
  - hosts: localhost
    tasks:
        - debug: msg="{{ myvar }}"

and create an extra-vars file like so:

myvar: 053507662074

When I execute the playbook like so:

ansible-playbook playbook.yml -e @extra_var_file.yml

The output is:

TASK [debug] *****************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": 5857305660
}

Notice how 053507662074 gets converted to 5857305660

If I set the variable on the command line like:

ansible-playbook playbook.yml -e "myvar=053507662074"

the output is as expected:

TASK [debug] *****************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": "053507662074"
}

** Can anyone help explain what's going on here? I used "type_debug" and the cmdline returns type of "unicode" whereas using an extra-vars file it returns type "int". Is there something I'm missing here like hex/oct conversion? **

Many thanks in advance

0 Answers
Related