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

int type is not maintained #31355

Closed
halberom opened this issue Oct 5, 2017 · 3 comments
Closed

int type is not maintained #31355

halberom opened this issue Oct 5, 2017 · 3 comments

Comments

@halberom
Copy link
Contributor

halberom commented Oct 5, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

set_fact

ANSIBLE VERSION
ansible-playbook 2.4.0.0
  config file = 
  configured module search path = [u'/Users/lynchg/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/lynchg/.virtualenvs/a2x/lib/python2.7/site-packages/ansible
  executable location = /Users/lynchg/.virtualenvs/a2x/bin/ansible-playbook
  python version = 2.7.13 (default, Dec 18 2016, 07:03:34) [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
CONFIGURATION

NA

OS / ENVIRONMENT

NA

SUMMARY

Trying to set a fact to an int fails, instead a string is created.

STEPS TO REPRODUCE

See gist - https://gist.github.com/halberom/859118d6da28493e17ad806e6b44e24c

Create following playbook

---
- hosts: localhost
  gather_facts: True
  connection: local
  tasks:
    - debug:
        var: ansible_memtotal_mb

    - shell: echo 12345
      register: mem

    - debug:
        var: mem

    - set_fact:
        ansible_memtotal_mb: "{{ mem.stdout|int }}"

    - debug:
        var: ansible_memtotal_mb
EXPECTED RESULTS

The final debug should show

TASK [debug] *******************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "ansible_memtotal_mb": 12345
}
ACTUAL RESULTS

The final debug shows the value as a string

TASK [debug] *******************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "ansible_memtotal_mb": "12345"
}
@halberom halberom changed the title type is not maintained int type is not maintained Oct 5, 2017
@halberom
Copy link
Contributor Author

halberom commented Oct 5, 2017

Apparently a workaround is to do

- set_fact:
  args: >
    {{ ('{"ansible_memtotal_mb": ' ~ mem.stdout ~ '}')|from_json }}

But that option is being deprecated

@halberom
Copy link
Contributor Author

halberom commented Oct 5, 2017

closing as dup of many other tickets

@halberom halberom closed this as completed Oct 5, 2017
@halberom
Copy link
Contributor Author

halberom commented Oct 5, 2017

See pallets/jinja#708 for ideal solution.

@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
None yet
Projects
None yet
Development

No branches or pull requests

1 participant