Skip to content

Commit

Permalink
change the way it works so it is var driven, update readme and role d…
Browse files Browse the repository at this point in the history
…efaults, needs testing
  • Loading branch information
sol1-matt committed Nov 27, 2024
1 parent 06fc8e4 commit dcc4749
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 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_enabled: false
netbox_local_settings_config_file: local_setting.py
----

Toggle `netbox_local_settings_enabled` to `true` to deploy local_settings.py for
NetBox. `netbox_local_settings_config_file` should be the path to your file - by
default, Ansible will search your playbook's `files/` directory for this.

NOTE: The destination file will always be `local_settings.py`, the source file name
can be unique.

[source,yaml]
----
netbox_napalm_enabled: false
Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ 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_enabled: false
netbox_local_settings_config_file: "netbox_local_settings.py"

netbox_napalm_enabled: false
netbox_napalm_packages:
- napalm
Expand Down
17 changes: 8 additions & 9 deletions tasks/deploy_netbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,24 @@

# local_settings.py
- name: Copy NetBox local_settings.py into shared (ignore if it doesn't exist)
copy:
src: "{{ playbook_dir }}/files/netbox/local_settings.py"
ansible.builtin.copy:
src: "{{ netbox_local_settings_config_file }}"
dest: "{{ netbox_shared_path }}/local_settings.py"
owner: "{{ netbox_user }}"
group: "{{ netbox_group }}"
ignore_errors: yes

- name: Check if local_settings.py file exists in shared
stat:
path: "{{ netbox_shared_path }}/local_settings.py"
register: netbox_local_settings_file_in_shared
when:
- netbox_local_settings_enabled
notify:
- reload netbox.service

- name: Symlink/Remove NetBox local_settings.py file into/from the active NetBox release
file:
src: "{{ netbox_shared_path + '/local_settings.py' if netbox_local_settings_file_in_shared.stat.exists else omit }}"
src: "{{ netbox_shared_path + '/local_settings.py' if netbox_local_settings_enabled else omit }}"
dest: "{{ netbox_config_path }}/local_settings.py"
owner: "{{ netbox_user }}"
group: "{{ netbox_group }}"
state: "{{ 'link' if netbox_local_settings_file_in_shared.stat.exists else 'absent' }}"
state: "{{ 'link' if netbox_local_settings_enabled else 'absent' }}"
notify:
- reload netbox.service

Expand Down

0 comments on commit dcc4749

Please sign in to comment.