From dcc474966e4a3097bfecf5ff9c2a2c3593a13c41 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Thu, 28 Nov 2024 10:22:56 +1100 Subject: [PATCH] change the way it works so it is var driven, update readme and role defaults, needs testing --- README.adoc | 13 +++++++++++++ defaults/main.yml | 3 +++ tasks/deploy_netbox.yml | 17 ++++++++--------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/README.adoc b/README.adoc index f738bec..4659682 100644 --- a/README.adoc +++ b/README.adoc @@ -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 diff --git a/defaults/main.yml b/defaults/main.yml index c281ae2..a642203 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 diff --git a/tasks/deploy_netbox.yml b/tasks/deploy_netbox.yml index bce9d86..4c5d7ac 100644 --- a/tasks/deploy_netbox.yml +++ b/tasks/deploy_netbox.yml @@ -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