Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer variables are converted to strings when referenced in other variables #18095

Closed
zacblazic opened this issue Oct 18, 2016 · 5 comments
Closed
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug.

Comments

@zacblazic
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

Variables

ANSIBLE VERSION
ansible 2.1.2.0
CONFIGURATION

No changes

OS / ENVIRONMENT

macOS Sierra (10.12)

SUMMARY

Variables defined as integers (without quotes) are converted to strings when using them in the definition of another variable.

STEPS TO REPRODUCE

---
- hosts: local
  connection: local
  gather_facts: no
  vars:
    some_integer: 5
    some_other_integer: "{{ some_integer }}"
  tasks:
    - debug: var=some_integer
    - debug: var=some_other_integer
EXPECTED RESULTS
LAY [local] *******************************************************************

TASK [debug] *******************************************************************
ok: [local] => {
    "some_integer": 5
}

TASK [debug] *******************************************************************
ok: [local] => {
    "some_other_integer": 5
}

PLAY RECAP *********************************************************************
local                      : ok=2    changed=0    unreachable=0    failed=0
ACTUAL RESULTS
LAY [local] *******************************************************************

TASK [debug] *******************************************************************
ok: [local] => {
    "some_integer": 5
}

TASK [debug] *******************************************************************
ok: [local] => {
    "some_other_integer": "5"
}

PLAY RECAP *********************************************************************
local                      : ok=2    changed=0    unreachable=0    failed=0
@ansibot ansibot added bug_report affects_2.1 This issue/PR affects Ansible v2.1 labels Oct 18, 2016
@alikins
Copy link
Contributor

alikins commented Oct 19, 2016

This seems to be a bug in how the output is shown. The variables themselves dont seem to end up as string types:

---
- hosts: localhost
  gather_facts: no
  vars:
    some_integer: 5
    some_other_integer: "{{ some_integer }}"
  tasks:
    - debug: var=some_integer
    - debug: var=some_other_integer
    - name: assert some_integer and some_other_integer is an int 5 and not a string "5"
      assert:
          that:
              - some_integer == 5
              - some_other_integer == 5

    - name: assert some_int is not a string
      assert:
          that:
              - some_integer != "5"
              - some_other_integer != "5"
PLAY [localhost] ***************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => {
    "some_integer": 5
}

TASK [debug] *******************************************************************
ok: [localhost] => {
    "some_other_integer": "5"
}

TASK [assert some_integer and some_other_integer is an int 5 and not a string "5"] ***
ok: [localhost] => {
    "changed": false, 
    "msg": "All assertions passed"
}

TASK [assert some_int is not a string] *****************************************
ok: [localhost] => {
    "changed": false, 
    "msg": "All assertions passed"
}

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=0   

@jctanner
Copy link
Contributor

Duplicate of #17992 (comment)

@dagwieers
Copy link
Member

dagwieers commented Sep 21, 2017

There is a light at the end of the tunnel. We made a change to Jinja2 so we don't see all variable types changed into strings. See: pallets/jinja#708

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@irsl
Copy link
Contributor

irsl commented Apr 11, 2018

Integers are evil!

@dagwieers
Copy link
Member

Some integers are more evil than others.

@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

6 participants