Best practice for custom script directory on NetBox server

442 views
Skip to first unread message

Christian Strauf

unread,
Feb 19, 2021, 5:38:04 AM2/19/21
to NetBox
Hi all!

I'm currently trying to figure out how to best manage Custom Scripts for our NetBox installations. We manage our NetBox servers with Ansible. Custom Scripts are in their own git repository. I'd like to simply clone the git repo to /opt/netbox/netbox/scripts. However, there's an __init__.py in that directory which leads to an error when I simply clone a git repo there. My question is: can I safely remove __init__.py? The other option would be to create a subdirectory in /opt/netbox/netbox/scripts to clone the Custom Scripts there, however, Python files in subdirectories don't seem to be evaluated by NetBox. How do you guys handle this? Is there a best practice to do this?

Christian

Brian Candler

unread,
Feb 19, 2021, 9:00:26 AM2/19/21
to NetBox
Overlaying one git repo on top of another git repo is a bit risky; "git pull" to upgrade the outer repo may complain.  But you could try it: put the zero-byte __init__.py in your own scripts repo (*)

Another option is to checkout your scripts repo somewhere else, and use ansible to install individual symlinks inside netbox's scripts directory, pointing to the real location.

(*) Python uses this to mark a directory of files as being a package.  However since python 3.3, there are also "implicit namespace packages":
I don't know if this means you can now get away without __init__.py, but it's safest to keep it.

Christian Strauf

unread,
Feb 22, 2021, 12:54:06 AM2/22/21
to NetBox
> Overlaying one git repo on top of another git repo is a bit risky; "git pull" to upgrade the outer repo may complain.
Yes, that's my fear that at some point this will get me into trouble.

I think that I'll try Glenn's suggestion and the symlink approach if the SCRIPTS_ROOT approach doesn't work.

Thank you both for your suggestions.

Christian

Reply all
Reply to author
Forward
0 new messages