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

Ansible mangles integers in lists #19851

Closed
fgimian opened this issue Jan 4, 2017 · 3 comments
Closed

Ansible mangles integers in lists #19851

fgimian opened this issue Jan 4, 2017 · 3 comments
Labels
affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@fgimian
Copy link

fgimian commented Jan 4, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible core

ANSIBLE VERSION
ansible 2.2.0.0
  config file = 
  configured module search path = Default w/o overrides
CONFIGURATION

None

OS / ENVIRONMENT

macOS Sierra 10.11.6
Python 2.7.13

SUMMARY

Lists containing integers are casted to strings when using set_fact

STEPS TO REPRODUCE
- hosts: localhost
  vars:
    numbers:
      - 123
      - 234

  tasks:
    - name: show numbers[0]
      debug: msg="{{ numbers[0] | to_json }}"

    - name: set fact_number = numbers[0]
      set_fact: fact_number="{{ numbers[0] }}"

    - name: show fact_number
      debug: msg="{{ fact_number | to_json }}"

    - name: set fact_number = numbers[0] and expilicitly cast to int
      set_fact: fact_number="{{ numbers[0] | int }}"

    - name: show fact_number
      debug: msg="{{ fact_number | to_json }}"
EXPECTED RESULTS
PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [show numbers[0]] *********************************************************
ok: [localhost] => {
    "msg": "123"
}

TASK [set fact_number = numbers[0]] ********************************************
ok: [localhost]

TASK [show fact_number] ********************************************************
ok: [localhost] => {
    "msg": "123"
}

TASK [set fact_number = numbers[0] and expilicitly cast to int] ****************
ok: [localhost]

TASK [show fact_number] ********************************************************
ok: [localhost] => {
    "msg": "123"
}
ACTUAL RESULTS
PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [show numbers[0]] *********************************************************
ok: [localhost] => {
    "msg": "123"
}

TASK [set fact_number = numbers[0]] ********************************************
ok: [localhost]

TASK [show fact_number] ********************************************************
ok: [localhost] => {
    "msg": "\"123\""
}

TASK [set fact_number = numbers[0] and expilicitly cast to int] ****************
ok: [localhost]

TASK [show fact_number] ********************************************************
ok: [localhost] => {
    "msg": "\"123\""
}
@ansibot ansibot added affects_2.2 This issue/PR affects Ansible v2.2 bug_report needs_triage Needs a first human triage before being processed. labels Jan 4, 2017
@alikins
Copy link
Contributor

alikins commented Jan 5, 2017

This sounds like a dupe of #17992

@alikins alikins removed the needs_triage Needs a first human triage before being processed. label Jan 5, 2017
@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@dagwieers
Copy link
Contributor

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

@dagwieers
Copy link
Contributor

Duplicate of #17992

@dagwieers dagwieers marked this as a duplicate of #17992 Nov 1, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

4 participants