From 6d4caca1037108df7f16ab651772c9cba6318cf0 Mon Sep 17 00:00:00 2001 From: "Simon Leinen (SWITCH)" Date: Fri, 10 May 2024 11:45:36 +0200 Subject: [PATCH 1/5] NetBox 4.0.0 and higher requires Python 3.10 or higher --- vars/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/main.yml b/vars/main.yml index f2d7d7f..3e4dac6 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -45,3 +45,4 @@ netbox_python_compat_matrix: - { netbox_version_min: '2.8.0', python_needed: '3.6.0' } - { netbox_version_min: '3.0.0', python_needed: '3.7.0' } - { netbox_version_min: '3.2.0', python_needed: '3.8.0' } + - { netbox_version_min: '4.0.0', python_needed: '3.10.0' } From 325cdd902661ef1170243526c89c97e7b560123b Mon Sep 17 00:00:00 2001 From: "Simon Leinen (SWITCH)" Date: Fri, 10 May 2024 11:58:40 +0200 Subject: [PATCH 2/5] User get_user_model() rather than importing User directly This is the recommended way to reference the user model according to the documentation[1]. It should be supported by at least Django 4, so can be assumed to work for NetBox releases older than 4.0 as well. I have only tested it with 4.0(.1) though. [1] https://docs.djangoproject.com/en/5.0/topics/auth/customizing/#referencing-the-user-model --- vars/main.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vars/main.yml b/vars/main.yml index f2d7d7f..369e153 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -14,8 +14,9 @@ _netbox_storages_map: sftpstorage: [] netbox_superuser_script: | - from django.contrib.auth.models import User + from django.contrib.auth import get_user_model from base64 import b64decode + User = get_user_model() password = b64decode("{{ netbox_superuser_password | b64encode }}").decode("UTF-8") query = User.objects.filter(username="{{ netbox_superuser_username }}") if not query.exists(): @@ -33,7 +34,8 @@ netbox_superuser_script: | netbox_superuser_token: | from users.models import Token - from django.contrib.auth.models import User + from django.contrib.auth import get_user_model + User = get_user_model() user = User.objects.get(username="{{ netbox_superuser_username }}") query = Token.objects.filter(user=user) if not query.exists(): From 09da2087dac4d898d8cd1a90373fd3315a79b8ca Mon Sep 17 00:00:00 2001 From: Adam Melong Date: Fri, 24 May 2024 01:12:31 -0400 Subject: [PATCH 3/5] Adding Amazon Linux 2023 support --- vars/amazon-2023.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 vars/amazon-2023.yml diff --git a/vars/amazon-2023.yml b/vars/amazon-2023.yml new file mode 100644 index 0000000..98dfe73 --- /dev/null +++ b/vars/amazon-2023.yml @@ -0,0 +1,21 @@ +--- +netbox_install_epel: false +_netbox_packages: + - gcc + - libpq-devel + - libxml2-devel + - libxslt-devel + - libffi-devel + - libjpeg-turbo-devel + - graphviz + - openssl-devel +_netbox_python_packages: + - python3 + - python3-devel + - python3-setuptools + - python3-psycopg2 + - python3-libselinux + - python3-pip +_netbox_python_binary: /usr/bin/python3.9 +_netbox_ldap_packages: + - openldap-devel From cb0270b313ad64bc308ce9a0f2737e638f59c345 Mon Sep 17 00:00:00 2001 From: Tyler Bigler <17618971+tyler-8@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:15:13 -0600 Subject: [PATCH 4/5] add reindex command for 3.4.5+ --- tasks/deploy_netbox.yml | 9 +++++++++ tasks/install_via_git.yml | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/tasks/deploy_netbox.yml b/tasks/deploy_netbox.yml index cf4baa2..7652e5b 100644 --- a/tasks/deploy_netbox.yml +++ b/tasks/deploy_netbox.yml @@ -242,5 +242,14 @@ or netbox_git and ( _netbox_git_contains_add_clearcache.rc == 0 and _netbox_git_contains_remove_clearcache.rc != 0 ) + - name: Rebuild the search cache (lazily) + django_manage: + command: "reindex --lazy" + app_path: "{{ netbox_current_path }}/netbox" + virtualenv: "{{ netbox_virtualenv_path }}" + when: + - netbox_stable and netbox_stable_version is version('3.4.5', '>') + or netbox_git and _netbox_git_contains_reindex_lazy.rc == 0 + become: true become_user: "{{ netbox_user }}" diff --git a/tasks/install_via_git.yml b/tasks/install_via_git.yml index a1a0615..80bcaa5 100644 --- a/tasks/install_via_git.yml +++ b/tasks/install_via_git.yml @@ -98,6 +98,15 @@ changed_when: False failed_when: "_netbox_git_contains_remove_clearcache.rc not in [0, 1]" + - name: Check existence of commit 5a4d8a7, adding the reindex lazy command + shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^5a4d8a71075a4529be8d5ef22d76d69861240f45' + args: + chdir: "{{ netbox_git_repo_path }}" + executable: /bin/bash + register: _netbox_git_contains_reindex_lazy + changed_when: False + failed_when: "_netbox_git_contains_reindex_lazy.rc not in [0, 1]" + become: true become_user: "{{ netbox_user }}" From 9d7d3598216be20c8d65b28bd66e24a856ff2235 Mon Sep 17 00:00:00 2001 From: Tyler Bigler <17618971+tyler-8@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:22:40 -0600 Subject: [PATCH 5/5] correct version check --- tasks/deploy_netbox.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/deploy_netbox.yml b/tasks/deploy_netbox.yml index 7652e5b..39bf78d 100644 --- a/tasks/deploy_netbox.yml +++ b/tasks/deploy_netbox.yml @@ -248,7 +248,7 @@ app_path: "{{ netbox_current_path }}/netbox" virtualenv: "{{ netbox_virtualenv_path }}" when: - - netbox_stable and netbox_stable_version is version('3.4.5', '>') + - netbox_stable and netbox_stable_version is version('3.4.4', '>') or netbox_git and _netbox_git_contains_reindex_lazy.rc == 0 become: true