-
-
Notifications
You must be signed in to change notification settings - Fork 80
Support for installing/configuring CUSTOM_VALIDATORS #194
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
base: develop
Are you sure you want to change the base?
Conversation
…l1-matt/ansible-role-netbox into feature/157_custom_validators
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments.
Also, it's preferred that you rebase against develop when syncing or amending commits for minor fixes, and then force pushing the result afterwards. This is mainly to keep commit history succinct—otherwise I'll squash them on merge but that'll result in losing your direct authorship (if that matters to you).
The wrapping on the doc updates is also a bit off—it doesn't seem to be following either Asciidoc convention or a character limit. The convention is to break lines at the end of a sentence (i.e. one sentence per line), but I've also wrapped on commas or end of a clause if a line is particularly long.
tasks/deploy_netbox.yml
Outdated
| notify: | ||
| - reload netbox.service | ||
|
|
||
| - name: Symlink/Remove NetBox local_settings.py file into/from the active NetBox release |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compared to local_settings.py, as far as I can tell custom_validators.py is not an expected file that gets imported in the upstream NetBox codebase. Having not tested this I'm assuming dropping it in the netbox folder makes it reachable from NetBox as custom_validators.XYZ and is why it's being symlinked here?
This isn't really an issue for stable NetBox deployments, but if I recall correctly it prevents updates for git-based deployments because the NetBox directory ends up having uncommitted changes. Which means we have to use a different method of making this file importable, maybe via installing the file into the virtualenv's site-packages directory directly?
|
Also extra note, in #191 I moved all configuration file changes into a block so the handler is only specified once. Something to look out for when rebasing. |
…re very simlar except for a different destination dir
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, this looks good overall.
The "action" pattern being used here in the role variables is kind of novel to me. Do you know of any other roles that handle files or something similar this way? From a practical perspective it seems fine, but from a UX perspective maybe a bit jarring? If any of the other contributors/other users passing by see this, what do you think? (probably better to ask now than have to think about backwards compatibility later if I do end up changing how the role variables work)
|
I guess I'll add Tyler (if you have the time) since he opened the original ticket too. |
The reason for the action pattern is because we don't have a fixed file. With similar "copy file to share and add/remove symlink" tasks currently in the role they work because the destination file is hard coded so we know the name of the file to remove if required. With the way I built this you can choose the name or have multiple files with different names for both validation so the name of a file to be remove can only be expressed with a variable. The though process behind the naming is
|
I kinda based it of ansible itself like Welcome anybody else's thoughts on this. |
|
@lae another change I made to get custom validators working was to change the configuration template so it was easier to setup the yml and output'd in a easier to read format. I've got that change on my branch readable_config I had 2 problems with the way it currently worked created config
I'm not sure what I've done here is "better", I think it is likely less safe, but it helped me with the 2 above problems. If this is something you'd like to consider I'm happy to tidy up that branch and submit another PR. But I acknowledge that this may not be the direction you'd like the role to go in which is why I kept it separate from deploying the files. |
Yeah, I totally get how it works and is intended to work, and it very much reminded me of the
...and now I noticed that I overlooked something in the earlier review. This comment from last year I think probably still applies here with the symlinks? But thinking about that comment I might be wrong—they shouldn't be tracked files so I normally |
This could be truma from setting up SSO :). The workflow I've done in the past is base install with ansible, have multiple possible files deploy'd to shared with ansible. Turn them on and off in config as I work on SSO without running ansible each time. Happy to remove the option.
The file names aren't fixed, users can named them whatever they like and have multiple files. The reference in Netbox is in the config to the filename. eg: are referenced in config as Same sort of thing with the python social auth pipelines.
I'll look into if |
Right. By |
I think what you are saying is I need to create a destination directory for validator and pipline files current From this Ansible can
The Netbox config would be something like this which is non standard and I'd need to test if it works This way seems to be a lot of complexity for the benefit of ansible configuration simplicity though I can see the benefit of the role making Netbox "clean" if humans do a bunch of manual stuff (also a bit of danger there too :). An alternate to not having a current directory would be to just use files and then detect and remove orphaned symlinks. I think having a shared directory and removing orphaned symlinks is the better alternative if you don't want explicit |
|
If the symlink method works for git-based installs (i.e. how this PR currently works) then the If the symlink method does cause update issues for git-based deploys, then I think, per this comment, that you can load those directories directly from e.g. |
|
the first scenario, in more concrete (pseudocode) terms, with a loop to help dedupe tasks: also, because those folders are our own folders (the entire shared folder technically is a convention of this role, not of NetBox) then we're well within our rights to say "if you manually put files in here then you should expect them to be removed if they're not defined in your Ansible deployment. So the above set of tasks would also kind of make the the second scenario sounds like it might simplify it a bit, no need for the symlink tasks and you avoid having orphaned symlinks when the current directory changes due to an update, and you'd just add the PYTHONPATH hack to the configuration.py (which can just always be a part of the template because it effectively does nothing if the folders are empty, but adding a conditional based on whether or not the role variables are empty would also be fine). |
|
I'll have a dig around and see if the symlink method works for git-based installs. Those 2 things will drive what happens with the files. |
#157 Adds support custom validation rules and custom validation logic.