Skip to content

Commit 9d1223d

Browse files
committed
Add capability to customize pip arguments
1 parent 0cb9afa commit 9d1223d

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

README.adoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,17 @@ NOTE: If you specify any plugins here, be sure to include the appropriate plugin
325325
You may also need to configure `netbox_local_settings_file` in some situations.
326326
Read https://netbox.readthedocs.io/en/stable/plugins/[Plugins] for more info.
327327

328+
[source,yaml]
329+
----
330+
netbox_pip_extra_args: []
331+
----
332+
333+
This variable controls the pip installation behavior:
334+
335+
- `netbox_pip_extra_args`: List of additional arguments passed to all `pip` commands in NetBox's virtualenv (e.g., `['-i', 'https://pypi.example.com/simple', '--trusted-host', 'pypi.example.com']`)
336+
337+
Note: Constraint files (`-c constraints.txt`) are automatically included for all pip operations in the NetBox virtualenv.
338+
328339
[source,yaml]
329340
----
330341
netbox_user: netbox

defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ netbox_napalm_enabled: false
8181
netbox_napalm_packages:
8282
- napalm
8383

84-
netbox_skip_pip_cache: false # If true, use '--no-cache-dir' for pip installs in NetBox venv
84+
netbox_pip_extra_args: [] # Additional pip arguments (e.g., ['--no-cache-dir', '-i', 'https://pypi.example.com/simple'])
8585
netbox_pip_packages: []
8686
netbox_pip_constraints:
8787
# Blacklist pynacl 1.3.0 due to https://github.com/pyca/pynacl/issues/479

tasks/deploy_netbox.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
- _netbox_config.SECRET_KEY is not defined
2222

2323
- name: Create NetBox virtualenv
24-
pip:
24+
ansible.builtin.pip:
2525
name:
2626
- pip
2727
- setuptools
@@ -62,7 +62,10 @@
6262
- name: Install needed Python dependencies
6363
ansible.builtin.pip:
6464
requirements: "{{ netbox_shared_path }}/requirements.txt"
65-
extra_args: "{{ (['-c {{ netbox_shared_path }}/constraints.txt'] + (['--no-cache-dir'] if netbox_skip_pip_cache else [])) | join(' ') }}"
65+
extra_args: >-
66+
{{ ['-c', netbox_shared_path + '/constraints.txt']
67+
+ (netbox_pip_extra_args | default([]))
68+
| join(' ') }}
6669
virtualenv: "{{ netbox_virtualenv_path }}"
6770
become: true
6871
become_user: "{{ netbox_user }}"
@@ -75,7 +78,10 @@
7578
name: "{{ item }}"
7679
state: present
7780
virtualenv: "{{ netbox_virtualenv_path }}"
78-
extra_args: "{{ '--no-cache-dir' if netbox_skip_pip_cache else omit }}"
81+
extra_args: >-
82+
{{ ['-c', netbox_shared_path + '/constraints.txt']
83+
+ (netbox_pip_extra_args | default([]))
84+
| join(' ') }}
7985
become: true
8086
become_user: "{{ netbox_user }}"
8187
retries: 2

tasks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
state: "{{ 'latest' if netbox_keep_uwsgi_updated else 'present' }}"
7575
umask: "0022"
7676
virtualenv: "{{ omit if not netbox_uwsgi_in_venv else netbox_virtualenv_path }}"
77+
extra_args: >-
78+
{{ netbox_pip_extra_args | default([])
79+
| join(' ') }}
7780
environment:
7881
PATH: "/usr/local/bin:{{ _path }}"
7982
notify:

0 commit comments

Comments
 (0)