Puppet:我尝试在 mainifest 中获取内存事实并得到错误 Operator '[]' is not applicable to an Undef Value

Puppet: I try get memory fact in mainifest and get error Operator '[]' is not applicable to an Undef Value

我想以字节为单位获取内存,我在清单中使用此代码

$memoryforapp = $facts['memory']['system']['total_bytes'] * 0.7

但是我收到了这个错误信息

Error: Operator '[]' is not applicable to an Undef Value.

起初 运行 在新服务器上,Puppet 没有事实 total_bytes 但有这些记忆事实:

memoryfree
memoryfree_mb
memorysize
memorysize_mb

然后我们可以按字节计算内存。我想知道75%的价值

$memoryforapp = ceiling(($::memorysize_mb * 1024) * 3/4)