Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible: how-to do math and get an integer?

If we assume that ansible_memtotal_mb is an odd number

- debug: msg="{{ ansible_memtotal_mb }}"

How can I divide ansible_memtotal_mb by 2, and convert the result to an integer:

- debug: msg="{{ ansible_memtotal_mb * 0.5 | int }}"

Obviously the latter did not work, because (if I am not mistaken) ansible_memtotal_mb * 0.5 returns a string and using the int filter, results to 0

Could you please advise?

like image 254
nskalis Avatar asked Jan 04 '23 02:01

nskalis


1 Answers

You applied int filter to the value 0.5.

You wanted to apply to the result of the expression, so:

- debug: msg="{{ (ansible_memtotal_mb * 0.5) | int }}"
like image 138
techraf Avatar answered Jan 11 '23 10:01

techraf