From 091d2d87278860232f314ee04247561b0621d29e Mon Sep 17 00:00:00 2001 From: Samuel Mutel <12967891+smutel@users.noreply.github.com> Date: Fri, 18 Mar 2022 15:55:43 +0100 Subject: [PATCH] enh: Update for Netbox 3.0 --- tasks/deploy_netbox.yml | 5 +++++ tasks/install_via_git.yml | 9 +++++++++ tasks/main.yml | 14 ++++++++------ vars/main.yml | 4 ++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/tasks/deploy_netbox.yml b/tasks/deploy_netbox.yml index 341c372..95c9036 100644 --- a/tasks/deploy_netbox.yml +++ b/tasks/deploy_netbox.yml @@ -52,6 +52,7 @@ loop: "{{ _netbox_python_deps }}" notify: - restart netbox.service + - restart netbox-rqworker.service - name: Generate NetBox configuration file template: @@ -65,6 +66,7 @@ py_compile.compile(f, c); os.remove(c)\"" notify: - reload netbox.service + - reload netbox-rqworker.service - name: Generate LDAP configuration for NetBox if enabled template: @@ -183,6 +185,9 @@ command: "invalidate all" app_path: "{{ netbox_current_path }}/netbox" virtualenv: "{{ netbox_virtualenv_path }}" + when: + - netbox_stable and netbox_stable_version is version('3.0.0', '<') + or netbox_git and _netbox_git_contains_invalidate_removed.rc == 0 become: true diff --git a/tasks/install_via_git.yml b/tasks/install_via_git.yml index bd7d2a2..235d980 100644 --- a/tasks/install_via_git.yml +++ b/tasks/install_via_git.yml @@ -60,6 +60,15 @@ changed_when: False failed_when: "_netbox_git_contains_housekeeping.rc not in [0, 1]" +- name: Check existence of commit 028c876, removing the invalidate command + shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^028c876bcafbaede2731f191512bbebe3f1b6a9e' + args: + chdir: "{{ netbox_git_repo_path }}" + executable: /bin/bash + register: _netbox_git_contains_invalidate_removed + changed_when: False + failed_when: "_netbox_git_contains_invalidate_removed.rc not in [0, 1]" + - name: Archive and extract snapshot of git repository shell: 'set -o pipefail; git archive "{{ netbox_git_version }}" | tar -x -C "{{ netbox_git_deploy_path }}"' args: diff --git a/tasks/main.yml b/tasks/main.yml index b264aa0..ae917cd 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -18,16 +18,18 @@ # Can't quite check the effective version of a git installation this early since # the repo isn't checked out, but most users will be on develop in the first # place so this dumb check should be good enough. -- name: Ensure the installed Python version is newer than 3.6.0 for NetBox 2.8+ +- name: Ensure Python version installed is compatible with this version of Netbox assert: that: - - "ansible_python_version is version('3.6.0', '>=')" + - "ansible_python_version is version(item.python_needed, '>=')" msg: > - NetBox 2.8.0+ requires Python 3.6+. Please either specify an older NetBox - version, upgrade to a newer distribution that provides Python 3.6+, or - set netbox_python_binary to an appropriate Python 3.6+ binary. + NetBox {{ item.netbox_version_min }} requires at least Python {{ item.python_needed }}. + Please either specify an older NetBox version, upgrade to a newer + distribution that provides Python at least {{ item.python_needed }}, or + set netbox_python_binary to an appropriate Python {{ item.python_needed }} binary. when: - - netbox_stable and netbox_stable_version is version('2.8.0', '>=') or netbox_git + - netbox_stable and netbox_stable_version is version(item.netbox_version_min, '>=') or netbox_git + loop: "{{ netbox_python_compat_matrix }}" - name: Create NetBox user group group: diff --git a/vars/main.yml b/vars/main.yml index cdd93fb..17c39de 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -39,3 +39,7 @@ netbox_superuser_token: | token = Token.objects.create(user=user) print("api-token: " + token.key) print("changed") + +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' }