Skip to content

Commit dcc4749

Browse files
committed
change the way it works so it is var driven, update readme and role defaults, needs testing
1 parent 06fc8e4 commit dcc4749

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
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_enabled: false
405+
netbox_local_settings_config_file: local_setting.py
406+
----
407+
408+
Toggle `netbox_local_settings_enabled` to `true` to deploy local_settings.py for
409+
NetBox. `netbox_local_settings_config_file` should be the path to your file - by
410+
default, Ansible will search your playbook's `files/` directory for this.
411+
412+
NOTE: The destination file will always be `local_settings.py`, the source file name
413+
can be unique.
414+
402415
[source,yaml]
403416
----
404417
netbox_napalm_enabled: false

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ 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_enabled: false
78+
netbox_local_settings_config_file: "netbox_local_settings.py"
79+
7780
netbox_napalm_enabled: false
7881
netbox_napalm_packages:
7982
- napalm

tasks/deploy_netbox.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,25 +135,24 @@
135135

136136
# local_settings.py
137137
- name: Copy NetBox local_settings.py into shared (ignore if it doesn't exist)
138-
copy:
139-
src: "{{ playbook_dir }}/files/netbox/local_settings.py"
138+
ansible.builtin.copy:
139+
src: "{{ netbox_local_settings_config_file }}"
140140
dest: "{{ netbox_shared_path }}/local_settings.py"
141141
owner: "{{ netbox_user }}"
142142
group: "{{ netbox_group }}"
143143
ignore_errors: yes
144-
145-
- name: Check if local_settings.py file exists in shared
146-
stat:
147-
path: "{{ netbox_shared_path }}/local_settings.py"
148-
register: netbox_local_settings_file_in_shared
144+
when:
145+
- netbox_local_settings_enabled
146+
notify:
147+
- reload netbox.service
149148

150149
- name: Symlink/Remove NetBox local_settings.py file into/from the active NetBox release
151150
file:
152-
src: "{{ netbox_shared_path + '/local_settings.py' if netbox_local_settings_file_in_shared.stat.exists else omit }}"
151+
src: "{{ netbox_shared_path + '/local_settings.py' if netbox_local_settings_enabled else omit }}"
153152
dest: "{{ netbox_config_path }}/local_settings.py"
154153
owner: "{{ netbox_user }}"
155154
group: "{{ netbox_group }}"
156-
state: "{{ 'link' if netbox_local_settings_file_in_shared.stat.exists else 'absent' }}"
155+
state: "{{ 'link' if netbox_local_settings_enabled else 'absent' }}"
157156
notify:
158157
- reload netbox.service
159158

0 commit comments

Comments
 (0)