-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Support for installing/configuring CUSTOM_VALIDATORS #194
base: develop
Are you sure you want to change the base?
Changes from all commits
dd54add
6c1c9d0
bdc808b
cd72640
b83128d
759a132
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -390,6 +390,33 @@ You may need to use this file for deploying certain NetBox plugins. | |
|
||
NOTE: Commenting or removing this role variable from your playbook will remove `local_settings.py` from your NetBox deployment. | ||
|
||
[source,yaml] | ||
---- | ||
netbox_custom_validators_enabled: true | ||
netbox_custom_validators_file: netbox_custom_validators.py | ||
---- | ||
|
||
Toggle `netbox_custom_validators_enabled` to `true` to create a custom validator file for | ||
NetBox. `netbox_custom_validators_file` should be the path to your custom validator file - by | ||
default, Ansible will search your playbook's `files/` directory for this. | ||
You can find an example in `examples/`. You will also need to set | ||
`netbox_config.CUSTOM_VALIDATORS` to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could use some more clarity. I don't think this is the exact value that users should be using, right? It depends on what validators they define in their validators file. |
||
|
||
``` | ||
CUSTOM_VALIDATORS: | | ||
{ | ||
"dcim.device": ( | ||
'custom_validators.DeviceValidator', | ||
), | ||
"virtualization.virtualmachine": ( | ||
'custom_validators.VirtualMachineValidator', | ||
) | ||
} | ||
``` | ||
|
||
TIP: By default, a local (non-LDAP) superuser will still be created by this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not relevant, I think this was accidentally copied and left in? |
||
role. If this is undesirable, consider toggling `netbox_superuser_enabled`. | ||
|
||
[source,yaml] | ||
---- | ||
netbox_napalm_enabled: false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,9 @@ netbox_ldap_config_template: netbox_ldap_config.py.j2 | |
|
||
# netbox_local_settings_file: "{{ playbook_dir }}/files/netbox/local_settings.py" | ||
|
||
netbox_custom_validators_enabled: false | ||
netbox_custom_validators_file: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest setting a non-empty default here, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually it looks like a default was specified in the README. This should be consistent with that. I'm fine with either filename. |
||
|
||
netbox_napalm_enabled: false | ||
netbox_napalm_packages: | ||
- napalm | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,6 +169,30 @@ | |
notify: | ||
- reload netbox.service | ||
|
||
# custom validators | ||
- name: Copy NetBox custom validators into shared | ||
ansible.builtin.copy: | ||
src: "{{ netbox_custom_validators_file }}" | ||
dest: "{{ netbox_shared_path }}/custom_validators.py" | ||
owner: "{{ netbox_user }}" | ||
group: "{{ netbox_group }}" | ||
ignore_errors: yes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Errors shouldn't be ignored here. |
||
when: | ||
- netbox_custom_validators_file is defined and netbox_custom_validators_enabled | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Compared to 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 |
||
file: | ||
src: "{{ netbox_shared_path + '/custom_validators.py' if netbox_custom_validators_enabled else omit }}" | ||
dest: "{{ netbox_current_path }}/netbox/custom_validators.py" | ||
owner: "{{ netbox_user }}" | ||
group: "{{ netbox_group }}" | ||
state: "{{ 'link' if netbox_custom_validators_enabled else 'absent' }}" | ||
notify: | ||
- reload netbox.service | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove extra newline. |
||
- name: Copy NetBox scripts into SCRIPTS_ROOT | ||
copy: | ||
src: "{{ item.src }}" | ||
|
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.
This appears to refer to an example but I don't see any changes in this PR to introduce that example.