Skip to content
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 local_settings.py settings override file #190

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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