Skip to content

Commit

Permalink
Merge pull request #190 from sol1-matt/feature/local_settings
Browse files Browse the repository at this point in the history
Support for local_settings.py settings override file
  • Loading branch information
lae authored Nov 29, 2024
2 parents b7e4945 + 3be9458 commit bb65f9d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,19 @@ You can find an example in `examples/`. You will also need to set
TIP: By default, a local (non-LDAP) superuser will still be created by this
role. If this is undesirable, consider toggling `netbox_superuser_enabled`.

[source,yaml]
----
# netbox_local_settings_file: "{{ playbook_dir }}/files/netbox/local_settings.py"
----

If you need to override any settings or extend the functionality in NetBox' `settings.py`
in a way that is not supported by the `configuration.py` (i.e. the `netbox_config` role variable),
you can set `netbox_local_settings_file` to a local file path in your playbook to deploy a `local_settings.py` file within NetBox.
This feature was https://github.com/netbox-community/netbox/issues/16127[introduced in NetBox v4.0.2].
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_napalm_enabled: false
Expand Down
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ netbox_requests_log: "file:{{ netbox_shared_path }}/requests.log"
netbox_ldap_enabled: false
netbox_ldap_config_template: netbox_ldap_config.py.j2

# netbox_local_settings_file: "{{ playbook_dir }}/files/netbox/local_settings.py"

netbox_napalm_enabled: false
netbox_napalm_packages:
- napalm
Expand Down
22 changes: 22 additions & 0 deletions tasks/deploy_netbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,28 @@
notify:
- reload netbox.service

# local_settings.py
- name: Copy NetBox local_settings.py into shared (ignore if it doesn't exist)
ansible.builtin.copy:
src: "{{ netbox_local_settings_file }}"
dest: "{{ netbox_shared_path }}/local_settings.py"
owner: "{{ netbox_user }}"
group: "{{ netbox_group }}"
when:
- netbox_local_settings_file is defined
notify:
- reload netbox.service

- name: Symlink/Remove NetBox local_settings.py file into/from the active NetBox release
ansible.builtin.file:
src: "{{ netbox_shared_path }}/local_settings.py"
dest: "{{ netbox_config_path }}/local_settings.py"
owner: "{{ netbox_user }}"
group: "{{ netbox_group }}"
state: "{{ 'link' if netbox_local_settings_file is defined else 'absent' }}"
notify:
- reload netbox.service

- name: Copy NetBox scripts into SCRIPTS_ROOT
copy:
src: "{{ item.src }}"
Expand Down

0 comments on commit bb65f9d

Please sign in to comment.