How to use arithmetic when setting a variable value in Ansible?

后端 未结 2 1083
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 05:04

I would like to use a system fact for a host times a number/percentage as a base for a variable. What I am trying to do specifically is use the ansible_memtotal_mb

2条回答
  •  情歌与酒
    2020-12-24 05:17

    One little thing to add. If you presume the math multiplication has precedence before jinja filter (| sign), you're wrong ;-)

    With values like

    total_rate: 150
    host_ratio: 14 # percentual

    "{{ total_rate*host_ratio*0.01|int }}" => 0 because 0.01|int = 0
    "{{ (total_rate*host_ratio*0.01)|int) }}" => 21 as one expects
    

提交回复
热议问题