saltstack-formulas / zabbix-formula

http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
50 stars 121 forks source link

Cannot set various config to 0 #103

Open OrangeDog opened 5 years ago

OrangeDog commented 5 years ago

For example, startagents: 0 will not work, because the template will omit the section because it's falsy.

OrangeDog commented 5 years ago

As a workaround, you can set them as a string instead: startagents: '0'

hatifnatt commented 5 years ago

It's a common issue. I think it's nothing to fix in formula, 0 without quotes i.e when it represent a number will interpret as False at Python / Jinja level. Personally I got into the habit of using quotes in yaml if I want something like0|1, yes|no or true|false to be used as a string.

hatifnatt commented 4 years ago

@OrangeDog do you think on formula side all variables mut be forced to string type?

myii commented 4 years ago

How about adding this specific value to pillar.example? Also, fixing any other examples in that file?

OrangeDog commented 4 years ago

Or have the template check the actual value instead of letting it cast to boolean.

hatifnatt commented 4 years ago

Sorry but I don't understand what do you mean by

have the template check the actual value instead of letting it cast to boolean.

Template render line with the option only if option value not empty string, None or False https://github.com/saltstack-formulas/zabbix-formula/blob/b83c7a02ae465baca17063aa9b83a84ff2d93d9e/zabbix/files/default/etc/zabbix/zabbix_server.conf.jinja#L305-L310

Python / Jinja interprets numeric zero 0 as False so it's required to convert value to string type to evaluate 0 as True. But this will require rewrite of all condition expressions in all template files in this formula. OR User can just quote values when they expeted to be string type.

OrangeDog commented 4 years ago
{% if settings.get('startalerters', defaults.get('startalerters', False)) == False -%}