Multiply with floating numbers

1,376 views
Skip to first unread message

Dewangga Bachrul Alam

unread,
Jan 16, 2016, 3:55:53 PM1/16/16
to Ansible Project
I've search some reference but still got no luck about divide operations in ansible.

# default/main.yml
mariadb_setmem: "{{ ansible_memtotal_mb *1024*1024 }}"
mariadb_misc_query_prealloc_size: "{{ mariadb_setmem *0.01 }}"

# task/main.yml
- name: Debugging Value
  debug:
    msg: "{{ mariadb_misc_query_prealloc_size }}"

And got error.
fatal: [vagrant01] => Failed to template {{ mariadb_misc_query_prealloc_size }}: Failed to template {{ mariadb_setmem *0.01 }}: an unexpected type error occurred. Error was can't multiply sequence by non-int of type 'float'

Is there any hints to got the results of the math operations and round it?
Any helps are appreciated.



Matt Martz

unread,
Jan 16, 2016, 6:12:04 PM1/16/16
to ansible...@googlegroups.com
That error indicates that you are trying to multiply a sequence, in this case I am assuming a string and a float.

mariadb_setmem is cast to a string.  You might try:

{{ mariadb_setmem|float * 0.01 }}

Also that functionality is provided by jinja2.  Math operations are described at http://jinja.pocoo.org/docs/dev/templates/#math
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4b11bd97-2d09-4def-823c-06e9ba35532a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Dewangga Bachrul Alam

unread,
Jan 17, 2016, 8:09:49 PM1/17/16
to Ansible Project
Hello Matt,

Thank you, it's working :)


Pada Minggu, 17 Januari 2016 06.12.04 UTC+7, Matt Martz menulis:
That error indicates that you are trying to multiply a sequence, in this case I am assuming a string and a float.

mariadb_setmem is cast to a string.  You might try:

{{ mariadb_setmem|float * 0.01 }}

Also that functionality is provided by jinja2.  Math operations are described at http://jinja.pocoo.org/docs/dev/templates/#math

On Saturday, January 16, 2016, Dewangga Bachrul Alam <dewan...@xtremenitro.org> wrote:
I've search some reference but still got no luck about divide operations in ansible.

# default/main.yml
mariadb_setmem: "{{ ansible_memtotal_mb *1024*1024 }}"
mariadb_misc_query_prealloc_size: "{{ mariadb_setmem *0.01 }}"

# task/main.yml
- name: Debugging Value
  debug:
    msg: "{{ mariadb_misc_query_prealloc_size }}"

And got error.
fatal: [vagrant01] => Failed to template {{ mariadb_misc_query_prealloc_size }}: Failed to template {{ mariadb_setmem *0.01 }}: an unexpected type error occurred. Error was can't multiply sequence by non-int of type 'float'

Is there any hints to got the results of the math operations and round it?
Any helps are appreciated.



--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages