Skip to content

Commit 5d0e0f7

Browse files
authored
Merge pull request #141 from smutel/Netbox3.0
Netbox 3.0 release
2 parents 36767c7 + 70619a0 commit 5d0e0f7

File tree

6 files changed

+71
-9
lines changed

6 files changed

+71
-9
lines changed

defaults/main.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
# defaults file for lae.netbox
33
netbox_stable: false
4-
netbox_stable_version: 2.10.10
4+
netbox_stable_version: 3.0.12
55
netbox_stable_uri: "https://github.com/netbox-community/netbox/archive/v{{ netbox_stable_version }}.tar.gz"
66

77
netbox_git: false
@@ -93,6 +93,9 @@ netbox_pip_constraints:
9393
# Blacklist django-rq 2.3.1 due to https://github.com/rq/django-rq/issues/421
9494
# https://github.com/netbox-community/netbox/issues/4633
9595
- 'django-rq!=2.3.1'
96+
# If you're using Netbox 2.11.3 or below, uncomment the below to fix database
97+
# migrations. https://github.com/pallets/markupsafe/issues/284
98+
# - 'MarkupSafe<2.1.0'
9699

97100
netbox_keep_uwsgi_updated: false
98101
netbox_uwsgi_options: {}

handlers/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@
2222
name: netbox-rqworker.service
2323
state: restarted
2424
daemon_reload: true
25+
26+
- name: reload netbox-rqworker.service
27+
systemd:
28+
name: netbox-rqworker.service
29+
state: reloaded

tasks/deploy_netbox.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
owner: "{{ netbox_user }}"
77
group: "{{ netbox_group }}"
88
loop:
9+
- "{{ netbox_home }}"
910
- "{{ netbox_releases_path }}"
1011
- "{{ netbox_shared_path }}"
1112
- "{{ _netbox_config.MEDIA_ROOT }}"
@@ -26,12 +27,25 @@
2627
owner: "{{ netbox_user }}"
2728
group: "{{ netbox_group }}"
2829

29-
- name: Create NetBox virtualenv and install needed Python dependencies
30+
- name: Create NetBox virtualenv
31+
pip:
32+
name:
33+
- pip
34+
- setuptools
35+
state: latest
36+
virtualenv: "{{ netbox_virtualenv_path }}"
37+
virtualenv_command: "{{ netbox_python_binary }} -m venv"
38+
become: true
39+
become_user: "{{ netbox_user }}"
40+
retries: 2
41+
register: _netbox_virtualenv_setup
42+
until: _netbox_virtualenv_setup is succeeded
43+
44+
- name: Install needed Python dependencies
3045
pip:
3146
requirements: "{{ netbox_current_path }}/requirements.txt"
3247
extra_args: "-c {{ netbox_current_path }}/constraints.txt"
3348
virtualenv: "{{ netbox_virtualenv_path }}"
34-
virtualenv_command: "{{ netbox_python_binary }} -m venv"
3549
become: true
3650
become_user: "{{ netbox_user }}"
3751
retries: 2
@@ -52,6 +66,7 @@
5266
loop: "{{ _netbox_python_deps }}"
5367
notify:
5468
- restart netbox.service
69+
- restart netbox-rqworker.service
5570

5671
- name: Generate NetBox configuration file
5772
template:
@@ -65,6 +80,7 @@
6580
py_compile.compile(f, c); os.remove(c)\""
6681
notify:
6782
- reload netbox.service
83+
- reload netbox-rqworker.service
6884

6985
- name: Generate LDAP configuration for NetBox if enabled
7086
template:
@@ -115,6 +131,17 @@
115131
group: "{{ netbox_group }}"
116132
loop: "{{ netbox_reports }}"
117133

134+
- name: Schedule daily housekeeping cronjob
135+
cron:
136+
name: "Netbox housekeeping"
137+
special_time: daily
138+
job: "{{ netbox_virtualenv_path }}/bin/python {{ netbox_current_path }}/netbox/manage.py housekeeping"
139+
user: "{{ netbox_user }}"
140+
cron_file: "netbox"
141+
when:
142+
- netbox_stable and netbox_stable_version is version('3.0.0', '>=')
143+
or netbox_git and _netbox_git_contains_housekeeping.rc == 0
144+
118145
- block:
119146
- name: Run database migrations for NetBox
120147
django_manage:
@@ -174,6 +201,9 @@
174201
command: "invalidate all"
175202
app_path: "{{ netbox_current_path }}/netbox"
176203
virtualenv: "{{ netbox_virtualenv_path }}"
204+
when:
205+
- netbox_stable and netbox_stable_version is version('3.0.0', '<')
206+
or netbox_git and _netbox_git_contains_invalidate_removed.rc == 0
177207

178208

179209
become: true

tasks/install_via_git.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@
5151
changed_when: False
5252
failed_when: "_netbox_git_contains_trace_paths.rc not in [0, 1]"
5353

54+
- name: Check existence of commit d87ec82, introducing nightly housekeeping command
55+
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^d87ec82fe34d92a84ee6f2a97ba0a87a53eed015'
56+
args:
57+
chdir: "{{ netbox_git_repo_path }}"
58+
executable: /bin/bash
59+
register: _netbox_git_contains_housekeeping
60+
changed_when: False
61+
failed_when: "_netbox_git_contains_housekeeping.rc not in [0, 1]"
62+
63+
- name: Check existence of commit 028c876, removing the invalidate command
64+
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^028c876bcafbaede2731f191512bbebe3f1b6a9e'
65+
args:
66+
chdir: "{{ netbox_git_repo_path }}"
67+
executable: /bin/bash
68+
register: _netbox_git_contains_invalidate_removed
69+
changed_when: False
70+
failed_when: "_netbox_git_contains_invalidate_removed.rc not in [0, 1]"
71+
5472
- name: Archive and extract snapshot of git repository
5573
shell: 'set -o pipefail; git archive "{{ netbox_git_version }}" | tar -x -C "{{ netbox_git_deploy_path }}"'
5674
args:

tasks/main.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@
1818
# Can't quite check the effective version of a git installation this early since
1919
# the repo isn't checked out, but most users will be on develop in the first
2020
# place so this dumb check should be good enough.
21-
- name: Ensure the installed Python version is newer than 3.6.0 for NetBox 2.8+
21+
- name: Ensure Python version installed is compatible with this version of Netbox
2222
assert:
2323
that:
24-
- "ansible_python_version is version('3.6.0', '>=')"
24+
- "ansible_python_version is version(item.python_needed, '>=')"
2525
msg: >
26-
NetBox 2.8.0+ requires Python 3.6+. Please either specify an older NetBox
27-
version, upgrade to a newer distribution that provides Python 3.6+, or
28-
set netbox_python_binary to an appropriate Python 3.6+ binary.
26+
NetBox {{ item.netbox_version_min }} requires at least Python {{ item.python_needed }}.
27+
Please either specify an older NetBox version, upgrade to a newer
28+
distribution that provides Python at least {{ item.python_needed }}, or
29+
set netbox_python_binary to an appropriate Python {{ item.python_needed }} binary.
2930
when:
30-
- netbox_stable and netbox_stable_version is version('2.8.0', '>=') or netbox_git
31+
- netbox_stable and netbox_stable_version is version(item.netbox_version_min, '>=') or netbox_git
32+
loop: "{{ netbox_python_compat_matrix }}"
3133

3234
- name: Create NetBox user group
3335
group:

vars/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ netbox_superuser_token: |
3939
token = Token.objects.create(user=user)
4040
print("api-token: " + token.key)
4141
print("changed")
42+
43+
netbox_python_compat_matrix:
44+
- { netbox_version_min: '2.8.0', python_needed: '3.6.0' }
45+
- { netbox_version_min: '3.0.0', python_needed: '3.7.0' }

0 commit comments

Comments
 (0)