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

deduplicate default values in ansible scripts #1675

Open
ltalirz opened this issue Sep 7, 2023 · 4 comments
Open

deduplicate default values in ansible scripts #1675

ltalirz opened this issue Sep 7, 2023 · 4 comments
Labels
kind/feature New feature request

Comments

@ltalirz
Copy link
Contributor

ltalirz commented Sep 7, 2023

In what area(s)?

/area configuration

Describe the feature

We currently repeat the default value for a given config value in a number of places in the ansible scripts.

At the same time, you have the schema which also defines a default value.

In principle, "all one would need to do" (to be figured out how) is to pass the config.yml through the schema validator before it is passed on to ansible. Then one could remove all these | default("...") in the ansible scripts, reducing duplication.

@ltalirz ltalirz added the kind/feature New feature request label Sep 7, 2023
@xpillons
Copy link
Collaborator

xpillons commented Sep 8, 2023

I don't know how feasible this can be if the default values are optional in the config file. Maybe we would have to define a global ansible var file for all the defaults.

@ltalirz
Copy link
Contributor Author

ltalirz commented Sep 8, 2023

This is typically taken care of by the schema validator library

I just checked and it appears there is no way to get the "filled with defaults" version from check-jsonschema but it is straighforward to get it from the underlying jsonschema library

https://python-jsonschema.readthedocs.io/en/stable/faq/#why-doesn-t-my-schema-s-default-property-set-the-default-on-my-instance

I.e. we would need to change our validate_schema.sh to use jsonschema directly
(probably anyhow make sense since we need to do this json <> yaml conversion back and forth)

@xpillons
Copy link
Collaborator

xpillons commented Sep 8, 2023

but I don't see how the default value will be incorporated in the config file if it doesn't exists.

@ltalirz
Copy link
Contributor Author

ltalirz commented Sep 8, 2023

config.yml + config.schema.json

via jsonschema

=> config.defaults.json with defaults populated (defaults = from JSON schema, see link above)

via yq

=> config.defaults.yml

Ansible would then read the config.defaults.yml instead of the config.yml

But yeah, there is a small downside in that we currently don't run the schema validation every time we run ansible - only for the install.sh.

So it would no longer be possible to just modify the config.yml and then run ansible afterwards.

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

No branches or pull requests

2 participants