Skip to content

Commit e4552c2

Browse files
committed
Merge pull request #79 from kdhlab/feature/remote-file-system
Remote file storage support
2 parents 837faf2 + a08d854 commit e4552c2

File tree

5 files changed

+53
-39
lines changed

5 files changed

+53
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.vscode/
33
.history
44
*.retry
5+
*.code-workspace

tasks/deploy_netbox.yml

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,18 @@
3838
register: _netbox_virtualenv_setup
3939
until: _netbox_virtualenv_setup is succeeded
4040

41-
- name: Install django-rq
41+
- name: Install selected optional Python dependencies
4242
pip:
43-
name: "django-rq"
43+
name: "{{ item }}"
44+
state: present
4445
virtualenv: "{{ netbox_virtualenv_path }}"
4546
become: True
4647
become_user: "{{ netbox_user }}"
4748
retries: 2
48-
register: _netbox_django_rq_install
49-
until: _netbox_django_rq_install is succeeded
49+
register: _netbox_pip_additional_install
50+
until: _netbox_pip_additional_install is succeeded
51+
when: (_netbox_python_deps | length) > 0
52+
loop: "{{ _netbox_python_deps }}"
5053

5154
- name: Generate NetBox configuration file
5255
template:
@@ -61,44 +64,21 @@
6164
notify:
6265
- reload netbox.service
6366

64-
- block:
65-
- name: Install django-auth-ldap if LDAP is enabled
66-
pip:
67-
name: django-auth-ldap
68-
virtualenv: "{{ netbox_virtualenv_path }}"
69-
become: True
70-
become_user: "{{ netbox_user }}"
71-
retries: 2
72-
register: _netbox_django_auth_ldap_install
73-
until: _netbox_django_auth_ldap_install is succeeded
74-
75-
- name: Generate LDAP configuration for NetBox if enabled
76-
template:
77-
src: "{{ netbox_ldap_config_template }}"
78-
dest: "{{ netbox_shared_path }}/ldap_config.py"
79-
owner: "{{ netbox_user }}"
80-
group: "{{ netbox_group }}"
81-
mode: 0640
82-
validate: "{{ netbox_virtualenv_path }}/bin/python -c \"import py_compile,os; f=r'%s';\
83-
c='/tmp/' + os.path.basename(os.path.dirname(f)) + '-' + os.path.basename(f) + 'c';\
84-
py_compile.compile(f, c); os.remove(c)\""
85-
notify:
86-
- reload netbox.service
67+
- name: Generate LDAP configuration for NetBox if enabled
68+
template:
69+
src: "{{ netbox_ldap_config_template }}"
70+
dest: "{{ netbox_shared_path }}/ldap_config.py"
71+
owner: "{{ netbox_user }}"
72+
group: "{{ netbox_group }}"
73+
mode: 0640
74+
validate: "{{ netbox_virtualenv_path }}/bin/python -c \"import py_compile,os; f=r'%s';\
75+
c='/tmp/' + os.path.basename(os.path.dirname(f)) + '-' + os.path.basename(f) + 'c';\
76+
py_compile.compile(f, c); os.remove(c)\""
77+
notify:
78+
- reload netbox.service
8779
when:
8880
- netbox_ldap_enabled
8981

90-
- name: Install napalm if NAPALM integration is enabled
91-
pip:
92-
name: "{{ netbox_napalm_packages }}"
93-
virtualenv: "{{ netbox_virtualenv_path }}"
94-
when:
95-
- netbox_napalm_enabled
96-
become: True
97-
become_user: "{{ netbox_user }}"
98-
retries: 2
99-
register: _netbox_napalm_install
100-
until: _netbox_napalm_install is succeeded
101-
10282
- name: Symlink NetBox configuration file into the active NetBox release
10383
file:
10484
src: "{{ netbox_shared_path }}/configuration.py"

tasks/load_variables.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
netbox_ldap_packages: "{{ _netbox_ldap_packages | list }}"
2828
when: netbox_ldap_packages is not defined
2929

30+
- name: Generate list of optional Python dependencies
31+
set_fact:
32+
_netbox_python_deps:
33+
- "{{ netbox_napalm_packages if netbox_napalm_enabled else [] }}"
34+
- "{{ 'django-auth-ldap' if netbox_ldap_enabled else [] }}"
35+
- "{{ 'django-storages' if _netbox_storages_module is defined else [] }}"
36+
- "{{ _netbox_storages_map[_netbox_storages_module] if _netbox_storages_module is defined else [] }}"
37+
38+
- name: Flatten that list of dependencies
39+
set_fact:
40+
_netbox_python_deps: "{{ _netbox_python_deps | flatten }}"
41+
3042
- name: Identify current execution PATH
3143
shell: "echo $PATH"
3244
register: _path_exec

tasks/validate_variables.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,15 @@
5656
- "(netbox_scripts | map(attribute='name') | map('regex_search', '^[a-z][a-z0-9_]*$') | select('string') | list | length) == (netbox_scripts | length)"
5757
- "(netbox_reports | map(attribute='name') | map('regex_search', '^[a-z][a-z0-9_]*$') | select('string') | list | length) == (netbox_reports | length)"
5858
msg: "Please ensure that your script/report module names start with a lowercase letter and contain only lowercase letters, numbers, and underscores."
59+
60+
- block:
61+
- name: Identify selected storage module
62+
set_fact:
63+
_netbox_storages_module: "{{ netbox_config.STORAGE_BACKEND | regex_search('(?<=storages\\.backends\\.).*(?=\\.)') }}"
64+
65+
- name: Ensure storage module is a valid option
66+
assert:
67+
that:
68+
- _netbox_storages_module in _netbox_storages_map
69+
msg: "Please ensure your STORAGE_BACKEND is correct."
70+
when: "'STORAGE_BACKEND' in netbox_config"

vars/main.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
netbox_config_path: "{{ netbox_current_path }}/netbox/netbox"
44
netbox_virtualenv_path: "{{ netbox_current_path }}/venv-py3"
55

6+
_netbox_storages_map:
7+
s3boto3: boto3
8+
apache_libcloud: "apache-libcloud"
9+
azure_storage: "django-storages[azure]"
10+
dropbox: "django-storages[dropbox]"
11+
gcloud: "django-storages[google]"
12+
ftp: []
13+
sftpstorage: []
14+
615
netbox_superuser_script: |
716
from django.contrib.auth.models import User
817
from base64 import b64decode

0 commit comments

Comments
 (0)