diff --git a/netbox/preload/prefixes_defaults.yml b/netbox/preload/prefixes_defaults.yml index 0fdb935f1..1788bb584 100644 --- a/netbox/preload/prefixes_defaults.yml +++ b/netbox/preload/prefixes_defaults.yml @@ -1,3 +1,6 @@ - prefix: 10.0.0.0/8 + site: NETBOX_DEFAULT_SITE - prefix: 172.16.0.0/12 + site: NETBOX_DEFAULT_SITE - prefix: 192.168.0.0/16 + site: NETBOX_DEFAULT_SITE diff --git a/netbox/scripts/netbox_init.py b/netbox/scripts/netbox_init.py index ab1aba957..65d6746b4 100755 --- a/netbox/scripts/netbox_init.py +++ b/netbox/scripts/netbox_init.py @@ -617,12 +617,16 @@ def main(): # only preload catch-all IP Prefixes if explicitly specified and they don't already exist if args.preloadPrefixes: + defaultSiteName = next(iter([x for x in args.netboxSites]), None) for loadType in ('vrfs', 'prefixes'): defaultFileName = os.path.join(tmpPreloadDir, f'{loadType}_defaults.yml') loadFileName = os.path.join(tmpPreloadDir, f'{loadType}.yml') if os.path.isfile(defaultFileName) and (not os.path.isfile(loadFileName)): try: - shutil.copyfile(defaultFileName, loadFileName) + with open(defaultFileName, 'r') as infile: + with open(loadFileName, 'w') as outfile: + for line in infile: + outfile.write(line.replace("NETBOX_DEFAULT_SITE", defaultSiteName)) except Exception: pass