calculate from facts

913 views
Skip to first unread message

Patrik Uytterhoeven

unread,
Feb 14, 2014, 5:59:30 PM2/14/14
to ansible...@googlegroups.com
hi, 

i would like to calculate 75% from from my memory 
if i read my pc memory from facts i can calculate it by multiplying it by 0.75
but that number will not always be a round number sometimes it will be a float

is there anyway to calculate the facts and drop what is behind the period ?

Brian Coca

unread,
Feb 17, 2014, 10:15:07 AM2/17/14
to ansible...@googlegroups.com
something like {{ansible_memory * 0.75|int }} ?


--
Brian Coca
Stultorum infinitus est numerus
0110000101110010011001010110111000100111011101000010000001111001011011110111010100100000011100110110110101100001011100100111010000100001
Pedo mellon a minno

Michael DeHaan

unread,
Feb 17, 2014, 10:35:30 AM2/17/14
to ansible...@googlegroups.com
Also, take a look at the "set_fact" module...


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Nico K.

unread,
Jul 24, 2014, 5:14:34 AM7/24/14
to ansible...@googlegroups.com
I'm actually using this in a template, however the behavior is not as expected:

someVar = {{ ansible_memtotal_mb / 4|int }}

The result is '256.0', same when I remove the |int and same when I do * 0.25.


Op maandag 17 februari 2014 16:15:07 UTC+1 schreef Brian Coca:

Michael DeHaan

unread,
Jul 24, 2014, 7:04:34 AM7/24/14
to ansible...@googlegroups.com
The precedence of the "|" is high in Jinja2.   You'll need some parenthesis.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages