We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
set_fact
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)]
NA
Trying to set a fact to an int fails, instead a string is created.
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
The final debug should show
TASK [debug] ******************************************************************************************************************************************************************************************************************************************************************* ok: [localhost] => { "ansible_memtotal_mb": 12345 }
The final debug shows the value as a string
TASK [debug] ******************************************************************************************************************************************************************************************************************************************************************* ok: [localhost] => { "ansible_memtotal_mb": "12345" }
The text was updated successfully, but these errors were encountered:
Apparently a workaround is to do
- set_fact: args: > {{ ('{"ansible_memtotal_mb": ' ~ mem.stdout ~ '}')|from_json }}
But that option is being deprecated
Sorry, something went wrong.
closing as dup of many other tickets
See pallets/jinja#708 for ideal solution.
No branches or pull requests
ISSUE TYPE
COMPONENT NAME
set_fact
ANSIBLE VERSION
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
EXPECTED RESULTS
The final debug should show
ACTUAL RESULTS
The final debug shows the value as a string
The text was updated successfully, but these errors were encountered: