Skip to content

Commit 2a90c40

Browse files
authored
Merge pull request #201 from tyler-8/pip_cache_option
Add support for custom pip extra args
2 parents 7c73157 + b04570c commit 2a90c40

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ netbox_napalm_enabled: false
8181
netbox_napalm_packages:
8282
- napalm
8383

84+
netbox_pip_extra_args: [] # Additional pip arguments (e.g., ['--no-cache-dir', '-i', 'https://pypi.example.com/simple'])
8485
netbox_pip_packages: []
8586
netbox_pip_constraints:
8687
# Blacklist pynacl 1.3.0 due to https://github.com/pyca/pynacl/issues/479

tasks/deploy_netbox.yml

Lines changed: 10 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"
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,6 +78,10 @@
7578
name: "{{ item }}"
7679
state: present
7780
virtualenv: "{{ netbox_virtualenv_path }}"
81+
extra_args: >-
82+
{{ (['-c', netbox_shared_path + '/constraints.txt']
83+
+ (netbox_pip_extra_args | default([])))
84+
| join(' ') }}
7885
become: true
7986
become_user: "{{ netbox_user }}"
8087
retries: 2
@@ -92,7 +99,7 @@
9299
content: |
93100
{% for dep in _netbox_python_deps %}
94101
{{ dep }}
95-
{% endfor %}
102+
{% endfor %}
96103
dest: "{{ netbox_current_path }}/local_requirements.txt"
97104
owner: "{{ netbox_user }}"
98105
group: "{{ netbox_group }}"

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)