Skip to content

Commit bb65f9d

Browse files
authored
Merge pull request #190 from sol1-matt/feature/local_settings
Support for local_settings.py settings override file
2 parents b7e4945 + 3be9458 commit bb65f9d

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

README.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,19 @@ You can find an example in `examples/`. You will also need to set
399399
TIP: By default, a local (non-LDAP) superuser will still be created by this
400400
role. If this is undesirable, consider toggling `netbox_superuser_enabled`.
401401

402+
[source,yaml]
403+
----
404+
# netbox_local_settings_file: "{{ playbook_dir }}/files/netbox/local_settings.py"
405+
----
406+
407+
If you need to override any settings or extend the functionality in NetBox' `settings.py`
408+
in a way that is not supported by the `configuration.py` (i.e. the `netbox_config` role variable),
409+
you can set `netbox_local_settings_file` to a local file path in your playbook to deploy a `local_settings.py` file within NetBox.
410+
This feature was https://github.com/netbox-community/netbox/issues/16127[introduced in NetBox v4.0.2].
411+
You may need to use this file for deploying certain NetBox plugins.
412+
413+
NOTE: Commenting or removing this role variable from your playbook will remove `local_settings.py` from your NetBox deployment.
414+
402415
[source,yaml]
403416
----
404417
netbox_napalm_enabled: false

defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ netbox_requests_log: "file:{{ netbox_shared_path }}/requests.log"
7474
netbox_ldap_enabled: false
7575
netbox_ldap_config_template: netbox_ldap_config.py.j2
7676

77+
# netbox_local_settings_file: "{{ playbook_dir }}/files/netbox/local_settings.py"
78+
7779
netbox_napalm_enabled: false
7880
netbox_napalm_packages:
7981
- napalm

tasks/deploy_netbox.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,28 @@
133133
notify:
134134
- reload netbox.service
135135

136+
# local_settings.py
137+
- name: Copy NetBox local_settings.py into shared (ignore if it doesn't exist)
138+
ansible.builtin.copy:
139+
src: "{{ netbox_local_settings_file }}"
140+
dest: "{{ netbox_shared_path }}/local_settings.py"
141+
owner: "{{ netbox_user }}"
142+
group: "{{ netbox_group }}"
143+
when:
144+
- netbox_local_settings_file is defined
145+
notify:
146+
- reload netbox.service
147+
148+
- name: Symlink/Remove NetBox local_settings.py file into/from the active NetBox release
149+
ansible.builtin.file:
150+
src: "{{ netbox_shared_path }}/local_settings.py"
151+
dest: "{{ netbox_config_path }}/local_settings.py"
152+
owner: "{{ netbox_user }}"
153+
group: "{{ netbox_group }}"
154+
state: "{{ 'link' if netbox_local_settings_file is defined else 'absent' }}"
155+
notify:
156+
- reload netbox.service
157+
136158
- name: Copy NetBox scripts into SCRIPTS_ROOT
137159
copy:
138160
src: "{{ item.src }}"

0 commit comments

Comments
 (0)