Skip to content

Commit dc9538f

Browse files
authored
Merge pull request #173 from lae/develop
release v1.0.5
2 parents 12bb61a + 7255caf commit dc9538f

15 files changed

+175
-97
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*.retry
55
*.code-workspace
66
*.sw?
7+
.venv

README.adoc

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Provided you have Ansible installed and are using defaults:
3636
[source,bash,subs="attributes"]
3737
----
3838
ansible-galaxy install geerlingguy.postgresql davidwittman.redis {role}
39+
ansible-galaxy collection install community.postgresql
3940
ansible-playbook -i your.server.fqdn, ~/.ansible/roles/{role}/examples/playbook_single_host_deploy.yml -K
4041
----
4142

@@ -47,6 +48,7 @@ You can also use Vagrant, if you prefer, to bring up NetBox at `localhost:8080`:
4748
[source,bash,subs="attributes"]
4849
----
4950
ansible-galaxy install geerlingguy.postgresql davidwittman.redis {role}
51+
ansible-galaxy collection install community.postgresql
5052
cd ~/.ansible/roles/{role}/
5153
vagrant up
5254
----
@@ -67,12 +69,23 @@ endif::[]
6769

6870
=== PostgreSQL
6971

70-
This role does not setup a PostgreSQL server (but will create a database if
71-
needed), so you'll need to setup a PostgreSQL server and create a database user
72-
separate from this role. Take a look at the _Example Playbook_ section.
72+
This role does not setup a PostgreSQL server (but will create a database if needed), so you'll need to setup a PostgreSQL server and create a database user separate from this role.
73+
Take a look at the _Example Playbook_ section.
7374

74-
WARNING: NetBox v2.2.0+ require PostgreSQL 9.4 at the minimum, which may not be
75-
available in your distribution's repos. You may want to use a role for this.
75+
In addition, for Ansible 2.10+, you may need to install the `community.postgresql` collection.
76+
It is recommended to specify this in your playbook's `requirements.yml` file.
77+
For example:
78+
79+
[source,yaml]
80+
----
81+
---
82+
collections:
83+
- name: community.postgresql
84+
version: 3.4.0
85+
----
86+
87+
WARNING: NetBox v2.2.0+ require PostgreSQL 9.4 at the minimum, which may not be available in your distribution's repos.
88+
You may want to use a role for this.
7689

7790
=== Redis
7891

@@ -231,6 +244,15 @@ Use this syntax if your redis is installed with sentinet architecture (multiple
231244
the second set of variables if you wish to split your cache database from your
232245
webhooks database.
233246

247+
[source,yaml]
248+
----
249+
netbox_rqworker_processes: 1
250+
----
251+
252+
Specify how many request queue workers should be started by the systemd service.
253+
You can leave this at the default of 1, unless you have a large number of reports,
254+
scripts and other background tasks.
255+
234256
[source,yaml]
235257
----
236258
netbox_config:
@@ -422,6 +444,15 @@ netbox_uwsgi_options: {}
422444
Specify extra configuration options to insert into `uwsgi.ini` here. This is
423445
expected to be a dictionary of key/value pairs, e.g. `buffer-size: 65535`.
424446

447+
[source,yaml]
448+
netbox_uwsgi_in_venv: false
449+
450+
Toggle `netbox_uwsgi_in_venv` to `true` if you want `uwsgi` to be installed in the same virtual environment as NetBox.
451+
Otherwise, it will be installed system-wide into the library path of the python version used to created the virtual environment (normal/legacy behavior).
452+
453+
WARNING: There's a possibility that this may become the default in a later version of this role (I think after further cross-platform testing).
454+
See https://github.com/lae/ansible-role-netbox/issues/144[issue #144] for further details.
455+
425456
[source,yaml]
426457
netbox_install_epel: true
427458

defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,6 @@ netbox_pip_constraints:
9999
# - 'MarkupSafe<2.1.0'
100100

101101
netbox_keep_uwsgi_updated: false
102+
netbox_uwsgi_in_venv: false
102103
netbox_uwsgi_options: {}
104+
netbox_rqworker_processes: 1

handlers/main.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919

2020
- name: restart netbox-rqworker.service
2121
systemd:
22-
name: netbox-rqworker.service
22+
name: "netbox-rqworker@{{ item }}.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
25+
with_sequence: count="{{ netbox_rqworker_processes }}"

molecule/default/converge.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
role_attr_flags: CREATEDB,NOSUPERUSER
2828
## REDIS server install
2929
redis_bind: 127.0.0.1
30+
netbox_rqworker_processes: 2
3031
roles:
3132
- geerlingguy.postgresql
3233
- davidwittman.redis

molecule/default/tests/test_default.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def test_services(host):
1010
services = [
1111
"netbox.socket",
1212
"netbox.service",
13-
"netbox-rqworker.service"
13+
"netbox-rqworker@1.service"
14+
"netbox-rqworker@2.service"
1415
]
1516
for service in services:
1617
s = host.service(service)

tasks/deploy_netbox.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
py_compile.compile(f, c); os.remove(c)\""
8181
notify:
8282
- reload netbox.service
83-
- reload netbox-rqworker.service
83+
- restart netbox-rqworker.service
8484

8585
- name: Generate LDAP configuration for NetBox if enabled
8686
template:
@@ -204,7 +204,7 @@
204204
app_path: "{{ netbox_current_path }}/netbox"
205205
virtualenv: "{{ netbox_virtualenv_path }}"
206206

207-
- name: Clear cached data in NetBox
207+
- name: Clear cached data in NetBox < 3
208208
django_manage:
209209
command: "invalidate all"
210210
app_path: "{{ netbox_current_path }}/netbox"
@@ -213,14 +213,16 @@
213213
- netbox_stable and netbox_stable_version is version('3.0.0', '<')
214214
or netbox_git and _netbox_git_contains_invalidate_removed.rc != 0
215215

216-
- name: Clear cached data in NetBox 3.2.3+
216+
- name: Clear cached data in NetBox 3.2.3 to 3.6
217217
django_manage:
218218
command: "clearcache"
219219
app_path: "{{ netbox_current_path }}/netbox"
220220
virtualenv: "{{ netbox_virtualenv_path }}"
221221
when:
222222
- netbox_stable and netbox_stable_version is version('3.2.2', '>')
223-
or netbox_git and _netbox_git_contains_add_clearcache.rc == 0
223+
and netbox_stable_version is version('3.7.0', '<')
224+
or netbox_git and ( _netbox_git_contains_add_clearcache.rc == 0
225+
and _netbox_git_contains_remove_clearcache.rc != 0 )
224226

225227
become: true
226228
become_user: "{{ netbox_user }}"

tasks/install_via_git.yml

Lines changed: 78 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -15,77 +15,91 @@
1515
group: "{{ netbox_group }}"
1616
state: directory
1717

18-
- name: Check existence of commit 1fb67b7, fixing issue netbox#2239
19-
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^1fb67b791f1a91c624dae4a1cd256e4cf3ddbb77'
20-
args:
21-
chdir: "{{ netbox_git_repo_path }}"
22-
executable: /bin/bash
23-
register: _netbox_git_contains_issue_2239_fix
24-
changed_when: false
25-
failed_when: "_netbox_git_contains_issue_2239_fix.rc not in [0, 1]"
18+
- name: Check for presence of various commits in git history
19+
block:
20+
- name: Check existence of commit 1fb67b7, fixing issue netbox#2239
21+
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^1fb67b791f1a91c624dae4a1cd256e4cf3ddbb77'
22+
args:
23+
chdir: "{{ netbox_git_repo_path }}"
24+
executable: /bin/bash
25+
register: _netbox_git_contains_issue_2239_fix
26+
changed_when: false
27+
failed_when: "_netbox_git_contains_issue_2239_fix.rc not in [0, 1]"
2628

27-
- name: Check existence of commit 3590ed3, renaming webhooks to tasks
28-
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^3590ed378d161dd724fad2dc73ff56da746352f8'
29-
args:
30-
chdir: "{{ netbox_git_repo_path }}"
31-
executable: /bin/bash
32-
register: _netbox_git_contains_tasks_rename
33-
changed_when: false
34-
failed_when: "_netbox_git_contains_tasks_rename.rc not in [0, 1]"
29+
- name: Check existence of commit 3590ed3, renaming webhooks to tasks
30+
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^3590ed378d161dd724fad2dc73ff56da746352f8'
31+
args:
32+
chdir: "{{ netbox_git_repo_path }}"
33+
executable: /bin/bash
34+
register: _netbox_git_contains_tasks_rename
35+
changed_when: false
36+
failed_when: "_netbox_git_contains_tasks_rename.rc not in [0, 1]"
3537

36-
- name: Check existence of commit 90dbe9b, renaming DEFAULT_TIMEOUT to RQ_DEFAULT_TIMEOUT
37-
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^90dbe9bf60ab3c72be10fd070c65c26dca543ca5'
38-
args:
39-
chdir: "{{ netbox_git_repo_path }}"
40-
executable: /bin/bash
41-
register: _netbox_git_contains_rq_timeout
42-
changed_when: False
43-
failed_when: "_netbox_git_contains_rq_timeout.rc not in [0, 1]"
38+
- name: Check existence of commit 90dbe9b, renaming DEFAULT_TIMEOUT to RQ_DEFAULT_TIMEOUT
39+
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^90dbe9bf60ab3c72be10fd070c65c26dca543ca5'
40+
args:
41+
chdir: "{{ netbox_git_repo_path }}"
42+
executable: /bin/bash
43+
register: _netbox_git_contains_rq_timeout
44+
changed_when: False
45+
failed_when: "_netbox_git_contains_rq_timeout.rc not in [0, 1]"
4446

45-
- name: Check existence of commit f560693, introducing trace_paths management command
46-
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^f560693748d1f35e79ad9d006a8a9b75ef5ae37b'
47-
args:
48-
chdir: "{{ netbox_git_repo_path }}"
49-
executable: /bin/bash
50-
register: _netbox_git_contains_trace_paths
51-
changed_when: False
52-
failed_when: "_netbox_git_contains_trace_paths.rc not in [0, 1]"
47+
- name: Check existence of commit f560693, introducing trace_paths management command
48+
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^f560693748d1f35e79ad9d006a8a9b75ef5ae37b'
49+
args:
50+
chdir: "{{ netbox_git_repo_path }}"
51+
executable: /bin/bash
52+
register: _netbox_git_contains_trace_paths
53+
changed_when: False
54+
failed_when: "_netbox_git_contains_trace_paths.rc not in [0, 1]"
5355

54-
- name: Check existence of commit e165dca, introducing mkdocs command during update
55-
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^7058d6ca5ae2901383874bcea5fedad31e165dca'
56-
args:
57-
chdir: "{{ netbox_git_repo_path }}"
58-
executable: /bin/bash
59-
register: _netbox_git_contains_mkdocs
60-
changed_when: False
61-
failed_when: "_netbox_git_contains_mkdocs.rc not in [0, 1]"
56+
- name: Check existence of commit e165dca, introducing mkdocs command during update
57+
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^7058d6ca5ae2901383874bcea5fedad31e165dca'
58+
args:
59+
chdir: "{{ netbox_git_repo_path }}"
60+
executable: /bin/bash
61+
register: _netbox_git_contains_mkdocs
62+
changed_when: False
63+
failed_when: "_netbox_git_contains_mkdocs.rc not in [0, 1]"
6264

63-
- name: Check existence of commit d87ec82, introducing nightly housekeeping command
64-
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^d87ec82fe34d92a84ee6f2a97ba0a87a53eed015'
65-
args:
66-
chdir: "{{ netbox_git_repo_path }}"
67-
executable: /bin/bash
68-
register: _netbox_git_contains_housekeeping
69-
changed_when: False
70-
failed_when: "_netbox_git_contains_housekeeping.rc not in [0, 1]"
65+
- name: Check existence of commit d87ec82, introducing nightly housekeeping command
66+
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^d87ec82fe34d92a84ee6f2a97ba0a87a53eed015'
67+
args:
68+
chdir: "{{ netbox_git_repo_path }}"
69+
executable: /bin/bash
70+
register: _netbox_git_contains_housekeeping
71+
changed_when: False
72+
failed_when: "_netbox_git_contains_housekeeping.rc not in [0, 1]"
7173

72-
- name: Check existence of commit 028c876, removing the invalidate command
73-
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^028c876bcafbaede2731f191512bbebe3f1b6a9e'
74-
args:
75-
chdir: "{{ netbox_git_repo_path }}"
76-
executable: /bin/bash
77-
register: _netbox_git_contains_invalidate_removed
78-
changed_when: False
79-
failed_when: "_netbox_git_contains_invalidate_removed.rc not in [0, 1]"
74+
- name: Check existence of commit 028c876, removing the invalidate command
75+
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^028c876bcafbaede2731f191512bbebe3f1b6a9e'
76+
args:
77+
chdir: "{{ netbox_git_repo_path }}"
78+
executable: /bin/bash
79+
register: _netbox_git_contains_invalidate_removed
80+
changed_when: False
81+
failed_when: "_netbox_git_contains_invalidate_removed.rc not in [0, 1]"
8082

81-
- name: Check existence of commit b172ae6, adding the clearcache command
82-
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^b172ae65d24f6dc161c4b609477a4547bb62a50b'
83-
args:
84-
chdir: "{{ netbox_git_repo_path }}"
85-
executable: /bin/bash
86-
register: _netbox_git_contains_add_clearcache
87-
changed_when: False
88-
failed_when: "_netbox_git_contains_add_clearcache.rc not in [0, 1]"
83+
- name: Check existence of commit b172ae6, adding the clearcache command
84+
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^b172ae65d24f6dc161c4b609477a4547bb62a50b'
85+
args:
86+
chdir: "{{ netbox_git_repo_path }}"
87+
executable: /bin/bash
88+
register: _netbox_git_contains_add_clearcache
89+
changed_when: False
90+
failed_when: "_netbox_git_contains_add_clearcache.rc not in [0, 1]"
91+
92+
- name: Check existence of commit 2d1f882, removing the clearcache command
93+
shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^2d1f88272497ca72d2e1eca8e291c04538c6810e'
94+
args:
95+
chdir: "{{ netbox_git_repo_path }}"
96+
executable: /bin/bash
97+
register: _netbox_git_contains_remove_clearcache
98+
changed_when: False
99+
failed_when: "_netbox_git_contains_remove_clearcache.rc not in [0, 1]"
100+
101+
become: true
102+
become_user: "{{ netbox_user }}"
89103

90104
- name: Archive and extract snapshot of git repository
91105
shell: 'set -o pipefail; git archive "{{ netbox_git_version }}" | tar -x -C "{{ netbox_git_deploy_path }}"'

tasks/load_variables.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@
5959
set_fact:
6060
_netbox_global_python: "{{ ansible_python_interpreter }}"
6161
when: ansible_python_interpreter is defined
62+
63+
- name: Set the execution uwsgi command
64+
set_fact:
65+
netbox_uwsgi_cmd: "/usr/bin/env uwsgi"
66+
when: "not netbox_uwsgi_in_venv | bool"

tasks/main.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
home: "{{ netbox_home }}"
4343

4444
- name: Ensure Postgres database exists (via socket)
45-
postgresql_db:
45+
community.postgresql.postgresql_db:
4646
name: "{{ netbox_database }}"
4747
login_user: "{{ netbox_database_user }}"
4848
login_unix_socket: "{{ netbox_database_socket }}"
@@ -54,7 +54,7 @@
5454
- netbox_database_host is not defined
5555

5656
- name: Ensure Postgres database exists (via TCP)
57-
postgresql_db:
57+
community.postgresql.postgresql_db:
5858
name: "{{ netbox_database }}"
5959
login_host: "{{ netbox_database_host }}"
6060
port: "{{ netbox_database_port }}"
@@ -72,6 +72,7 @@
7272
name: uwsgi
7373
state: "{{ 'latest' if netbox_keep_uwsgi_updated else 'present' }}"
7474
umask: "0022"
75+
virtualenv: "{{ omit if not netbox_uwsgi_in_venv else netbox_virtualenv_path }}"
7576
environment:
7677
PATH: "/usr/local/bin:{{ _path }}"
7778
notify:
@@ -106,7 +107,7 @@
106107
- name: Install NetBox-rqworker service unit file
107108
template:
108109
src: netbox-rqworker.service.j2
109-
dest: /lib/systemd/system/netbox-rqworker.service
110+
dest: /lib/systemd/system/netbox-rqworker@.service
110111
notify:
111112
- restart netbox-rqworker.service
112113

@@ -121,9 +122,10 @@
121122

122123
- name: Start and enable netbox-rqworker.service
123124
systemd:
124-
name: netbox-rqworker.service
125+
name: "netbox-rqworker@{{ item }}.service"
125126
state: started
126127
enabled: true
128+
with_sequence: count="{{ netbox_rqworker_processes }}"
127129

128130
- name: Restore the previous Ansible Python interpreter
129131
set_fact:

0 commit comments

Comments
 (0)