Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set various config to 0 #103

Open
OrangeDog opened this issue Jan 10, 2019 · 7 comments
Open

Cannot set various config to 0 #103

OrangeDog opened this issue Jan 10, 2019 · 7 comments

Comments

@OrangeDog
Copy link

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

@OrangeDog
Copy link
Author

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

@hatifnatt
Copy link
Collaborator

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
Copy link
Collaborator

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

@myii
Copy link
Member

myii commented Jul 8, 2020

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

@OrangeDog
Copy link
Author

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

@hatifnatt
Copy link
Collaborator

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

# Default:
# StartAlerters=3
{% if settings.get('startalerters', defaults.get('startalerters', False)) -%}
StartAlerters={{ settings.get('startalerters', defaults.startalerters) }}
{% endif %}
{% endif -%}

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
Copy link
Author

{% if settings.get('startalerters', defaults.get('startalerters', False)) == False -%}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants