Skip to content

[change] Added openwisp2_pip_extra_args: "--upgrade" to force pip to upgrade deps#575

Merged
nemesifier merged 9 commits into
openwisp:masterfrom
Piyushrathoree:feat/upgrade-pip-deps-572
Jun 3, 2026
Merged

[change] Added openwisp2_pip_extra_args: "--upgrade" to force pip to upgrade deps#575
nemesifier merged 9 commits into
openwisp:masterfrom
Piyushrathoree:feat/upgrade-pip-deps-572

Conversation

@Piyushrathoree

Copy link
Copy Markdown
Contributor

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #572

Description of Changes

update the pip.yml file with extra-args:"--upgrade" which make sure that every dependency is updated.

@Piyushrathoree Piyushrathoree changed the title [ansible-openwisp2] Upgrade pip deps from requiremeents on rerun #572 [ansible-openwisp2] Upgrade pip deps from requirements on rerun #572 Dec 4, 2025
@Piyushrathoree Piyushrathoree changed the title [ansible-openwisp2] Upgrade pip deps from requirements on rerun #572 [ansible-openwisp2] Upgrade pip deps from requirements on rerun Dec 4, 2025
@Piyushrathoree

Copy link
Copy Markdown
Contributor Author

@pandafy PTAL

@pandafy pandafy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start @Piyushrathoree!

I am afraid that --upgrade might not always work when we use tarball URL as source. E.g. when we set openwisp-controller version in the ansible playbook

openwisp2_controller_version: openwisp-controller @ https://github.com/openwisp/openwisp-controller/tarball/master

In such scenarios, we would need to use state: forcereinstall.

Using forcereinstall by default will slow down the playbook, since it will make pip reinstall packages even when the latest package have been installed.

I can think of exposing pip.extra_args argument through ansible variable openwisp2_pip_extra_args. The default value for this argument will be openwisp2_pip_extra_args: "--upgrade". When needed, the user can override the variable in the playbook to use `openwisp2_pip_extra_args: "--upgrade --force-reinstall" which will force-reinstall the packages.

We will need to add this new variable in https://github.com/openwisp/ansible-openwisp2/blob/master/docs/user/role-variables.rst, and explain the usage with a comment. You can take reference from other settings mentioned in the file.

value --upgrade and can be overridden with
--upgrade --force-reinstall
@Piyushrathoree

Piyushrathoree commented Dec 10, 2025

Copy link
Copy Markdown
Contributor Author

Good start @Piyushrathoree!

I am afraid that --upgrade might not always work when we use tarball URL as source. E.g. when we set openwisp-controller version in the ansible playbook

openwisp2_controller_version: openwisp-controller @ https://github.com/openwisp/openwisp-controller/tarball/master

In such scenarios, we would need to use state: forcereinstall.

Using forcereinstall by default will slow down the playbook, since it will make pip reinstall packages even when the latest package have been installed.

I can think of exposing pip.extra_args argument through ansible variable openwisp2_pip_extra_args. The default value for this argument will be openwisp2_pip_extra_args: "--upgrade". When needed, the user can override the variable in the playbook to use `openwisp2_pip_extra_args: "--upgrade --force-reinstall" which will force-reinstall the packages.

We will need to add this new variable in https://github.com/openwisp/ansible-openwisp2/blob/master/docs/user/role-variables.rst, and explain the usage with a comment. You can take reference from other settings mentioned in the file.

thanks @pandafy
made some changes according to what you've said , please take a look .

Comment thread defaults/main.yml Outdated
Comment on lines +34 to +37
# Extra arguments passed to pip when reinstalling Python packages with --force-reinstall
# By default, packages are upgraded on each playbook run.
# Can be overridden, for example:
# openwisp2_pip_extra_args: "--upgrade --force-reinstall"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Extra arguments passed to pip when reinstalling Python packages with --force-reinstall
# By default, packages are upgraded on each playbook run.
# Can be overridden, for example:
# openwisp2_pip_extra_args: "--upgrade --force-reinstall"
# Extra arguments passed to pip when installing Python packages.
# By default, packages are upgraded on each playbook run.
# Can be overridden, for example:
# openwisp2_pip_extra_args: "--upgrade --force-reinstall"

@coderabbitai

coderabbitai Bot commented Mar 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f6d09f5a-ab6f-484c-9294-0309e02983d0

📥 Commits

Reviewing files that changed from the base of the PR and between b5d9f31 and c4f124d.

📒 Files selected for processing (2)
  • defaults/main.yml
  • tasks/pip.yml
📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{yml,yaml,j2}

📄 CodeRabbit inference engine (AGENTS.md)

Avoid unnecessary blank lines inside Jinja, YAML, and shell blocks.

Files:

  • defaults/main.yml
  • tasks/pip.yml
**/*.{yml,yaml,j2,sh}

📄 CodeRabbit inference engine (AGENTS.md)

Write comments only when they explain why code is shaped a certain way. Put comments before the relevant block instead of scattering them inside it.

Files:

  • defaults/main.yml
  • tasks/pip.yml
🔇 Additional comments (2)
defaults/main.yml (1)

239-241: LGTM!

tasks/pip.yml (1)

25-25: LGTM!

Also applies to: 63-63, 79-79, 95-95, 111-111


📝 Walkthrough

Walkthrough

Adds a new public Ansible variable openwisp2_pip_extra_args (default "--upgrade") in role defaults, documents it in role variables, and forwards it as extra_args to multiple ansible.builtin.pip tasks so pip installs for controller, requirements files, optional components, DB drivers, and celery-email can receive additional pip CLI arguments.

Sequence Diagram(s)

sequenceDiagram
  participant Playbook
  participant Defaults
  participant PipModule
  participant RequirementsFiles
  Playbook->>Defaults: read openwisp2_pip_extra_args
  Playbook->>PipModule: call ansible.builtin.pip with extra_args={{ openwisp2_pip_extra_args }}
  PipModule->>RequirementsFiles: install/update packages from requirements files
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description covers most required sections with checklist completed, issue reference (#572), and change description. However, the description states documentation was NOT updated, but docs/user/role-variables.rst was actually modified. Update the checklist to mark documentation as updated since docs/user/role-variables.rst was modified. Also expand the description to better explain the implementation details.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title correctly follows the required format with [change] prefix and clearly describes the addition of the openwisp2_pip_extra_args variable with --upgrade default value.
Linked Issues check ✅ Passed The PR fully implements the feature requested in #572 by adding openwisp2_pip_extra_args variable with --upgrade default and applying it to all pip tasks, allowing users to override it for force-reinstalls.
Out of Scope Changes check ✅ Passed All changes are directly scoped to addressing #572: adding the pip extra_args variable, documenting it, and applying it to pip tasks. No unrelated modifications detected.
Bug Fixes ✅ Passed This PR is a feature request (issue #572 labeled [feature]), not a bug fix. The custom check applies only to bug fixes in core functionality, making it not applicable to this PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
docs/user/role-variables.rst (1)

34-38: ⚠️ Potential issue | 🟡 Minor

Clarify the openwisp2_pip_extra_args description to match actual default behavior.

Line 34 implies --force-reinstall is part of the normal behavior, but Line 38 sets default to --upgrade. Please describe --force-reinstall as an optional override example only.

✏️ Proposed doc wording
-        # Extra arguments passed to pip when reinstalling Python packages with --force-reinstall 
+        # Extra arguments passed to pip when installing Python packages.
         # By default, packages are upgraded on each playbook run.
         # Can be overridden, for example:
         # openwisp2_pip_extra_args: "--upgrade --force-reinstall"

As per coding guidelines, "Changes: If the change affects behavior that is already documented, the documentation must be updated to reflect the new behavior".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/user/role-variables.rst` around lines 34 - 38, The documentation
incorrectly implies --force-reinstall is part of default behavior for
openwisp2_pip_extra_args; update the description to state that the default value
of openwisp2_pip_extra_args is "--upgrade" (packages are upgraded on each
playbook run) and mention --force-reinstall only as an optional override example
(e.g., openwisp2_pip_extra_args: "--upgrade --force-reinstall") so the docs
reflect actual default behavior rather than suggesting force-reinstall is
applied by default.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@docs/user/role-variables.rst`:
- Around line 34-38: The documentation incorrectly implies --force-reinstall is
part of default behavior for openwisp2_pip_extra_args; update the description to
state that the default value of openwisp2_pip_extra_args is "--upgrade"
(packages are upgraded on each playbook run) and mention --force-reinstall only
as an optional override example (e.g., openwisp2_pip_extra_args: "--upgrade
--force-reinstall") so the docs reflect actual default behavior rather than
suggesting force-reinstall is applied by default.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d421369a-1cb6-4428-aafd-6c7db36bfc06

📥 Commits

Reviewing files that changed from the base of the PR and between fab8fc4 and 6285e66.

📒 Files selected for processing (3)
  • defaults/main.yml
  • docs/user/role-variables.rst
  • tasks/pip.yml
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build debian12
  • GitHub Check: Build ubuntu2204
  • GitHub Check: Build ubuntu2404
  • GitHub Check: Build debian13
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{md,rst,txt}

📄 CodeRabbit inference engine (Custom checks)

**/*.{md,rst,txt}: Changes: If the change affects behavior that is already documented, the documentation must be updated to reflect the new behavior
Features: Documentation must mention the new feature; for heavily UI-related features, a new section or page is appropriate

Files:

  • docs/user/role-variables.rst
🔇 Additional comments (2)
defaults/main.yml (1)

237-238: Good default and variable exposure.

Introducing openwisp2_pip_extra_args with default --upgrade is a clean, backward-compatible way to make reruns upgrade-aware while preserving override flexibility.

tasks/pip.yml (1)

46-46: Nice reuse of configurable pip args across requirements installs.

The additions consistently parameterize pip extra_args in the affected requirement-based tasks, which improves maintainability and supports override scenarios from inventory/group vars.

Also applies to: 126-126, 158-158, 177-177, 217-217

coderabbitai[bot]
coderabbitai Bot previously approved these changes Mar 14, 2026
@openwisp-companion

Copy link
Copy Markdown

Hi @Piyushrathoree 👋,

This pull request has been marked as stale due to 139 days of inactivity after changes were requested.

As a result, any linked issues are being unassigned from you so other contributors can pick them up.

However, you can still continue working on this PR! If you push new commits or respond to the review feedback:

  • The issue will be reassigned to you
  • Your contribution is still very welcome

If you need more time or have questions about the requested changes, please let us know. We're happy to help! 🤝

@openwisp-companion

Copy link
Copy Markdown

Hi @Piyushrathoree 👋,

This PR has been inactive for 140 days since changes were requested. Are you still working on it?

If yes, push new commits or reply to let us know. If you've moved on, please close the PR or comment so another contributor can pick it up.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
tasks/pip.yml (1)

17-113: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Major package tasks should also accept extra_args to support forcereinstall.

The PR discussion noted that tarball URL packages need state: forcereinstall or --force-reinstall in extra_args because --upgrade alone doesn't detect changes when the tarball URL is static. Currently, only requirements-file tasks receive openwisp2_pip_extra_args, so even if a user overrides the variable to "--upgrade --force-reinstall", these major packages (controller, network-topology, firmware-upgrader, monitoring, radius) won't be force-reinstalled.

For static tarball URLs like https://.../tarball/master, state: latest cannot detect content changes since the URL remains constant. This leaves a gap: users cannot force-reinstall tarball-based packages through the new configuration variable.

🔧 Proposed fix: Add extra_args to tarball package tasks

Apply to each of the five major package installation tasks (controller, network-topology, firmware-upgrader, monitoring, radius):

 - name: Install openwisp2 controller and its dependencies
   ansible.builtin.pip:
     name:
       - "{{ openwisp2_controller_version }}"
       - service_identity
     state: latest
     virtualenv: "{{ virtualenv_path }}"
     virtualenv_python: "{{ openwisp2_python }}"
+    extra_args: "{{ openwisp2_pip_extra_args }}"
   environment:
     LC_CTYPE: "en_US.UTF-8"
   notify: Reload application

Repeat this pattern for the network-topology (line 57), firmware-upgrader (line 72), monitoring (line 87), and radius (line 102) tasks.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tasks/pip.yml` around lines 17 - 113, The five pip install tasks for the
major packages (the tasks titled "Install openwisp2 controller and its
dependencies", "Install openwisp2 network topology and its dependencies",
"Install openwisp firmware upgrader and its dependencies", "Install openwisp
monitoring and its dependencies", and "Install openwisp2_radius and its
dependencies") must accept the extra_args variable so tarball installs can be
force-reinstalled; add extra_args: "{{ openwisp2_pip_extra_args }}" to each of
those ansible.builtin.pip task blocks (keeping their existing name, when
conditions like
openwisp2_network_topology/openwisp2_firmware_upgrader/openwisp2_monitoring/openwisp2_radius,
virtualenv and virtualenv_python unchanged) so users can pass
"--force-reinstall" or other pip flags via openwisp2_pip_extra_args.
defaults/main.yml (1)

238-238: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Enhance the comment to match documentation clarity.

The inline comment is too brief and doesn't explain the variable's purpose or usage. The documentation in docs/user/role-variables.rst provides a much clearer explanation that should be reflected here.

📝 Suggested comment improvement
-# variable for default deps upgrade 
+# Extra arguments passed to pip when installing Python packages from requirements files.
+# By default, packages are upgraded on each playbook run.
+# Can be overridden, for example: openwisp2_pip_extra_args: "--upgrade --force-reinstall"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@defaults/main.yml` at line 238, Replace the terse inline comment "# variable
for default deps upgrade" with a descriptive comment that matches the wording in
docs/user/role-variables.rst: state the variable's name, purpose, accepted
values (e.g., true/false or list), default behavior, and example usage; update
the comment directly above the variable definition so readers can understand
what the "default deps upgrade" setting does and how to use it without opening
the docs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@defaults/main.yml`:
- Line 238: Replace the terse inline comment "# variable for default deps
upgrade" with a descriptive comment that matches the wording in
docs/user/role-variables.rst: state the variable's name, purpose, accepted
values (e.g., true/false or list), default behavior, and example usage; update
the comment directly above the variable definition so readers can understand
what the "default deps upgrade" setting does and how to use it without opening
the docs.

In `@tasks/pip.yml`:
- Around line 17-113: The five pip install tasks for the major packages (the
tasks titled "Install openwisp2 controller and its dependencies", "Install
openwisp2 network topology and its dependencies", "Install openwisp firmware
upgrader and its dependencies", "Install openwisp monitoring and its
dependencies", and "Install openwisp2_radius and its dependencies") must accept
the extra_args variable so tarball installs can be force-reinstalled; add
extra_args: "{{ openwisp2_pip_extra_args }}" to each of those
ansible.builtin.pip task blocks (keeping their existing name, when conditions
like
openwisp2_network_topology/openwisp2_firmware_upgrader/openwisp2_monitoring/openwisp2_radius,
virtualenv and virtualenv_python unchanged) so users can pass
"--force-reinstall" or other pip flags via openwisp2_pip_extra_args.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4159f5ee-33d0-4887-8bbf-b9cdd5314696

📥 Commits

Reviewing files that changed from the base of the PR and between 6285e66 and 1d35ef6.

📒 Files selected for processing (2)
  • defaults/main.yml
  • tasks/pip.yml
📜 Review details
🔇 Additional comments (6)
defaults/main.yml (1)

239-239: LGTM!

tasks/pip.yml (5)

41-53: LGTM!


122-133: LGTM!


155-166: LGTM!


175-186: LGTM!


216-229: LGTM!

@nemesifier nemesifier changed the title [ansible-openwisp2] Upgrade pip deps from requirements on rerun [change] Added openwisp2_pip_extra_args: "--upgrade" to force pip to upgrade deps Jun 3, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to In progress in 26.06 Release Jun 3, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in 26.06 Release Jun 3, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
docs/user/role-variables.rst (1)

34-34: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Documentation incorrectly describes the variable's behavior.

Line 34 states "when reinstalling Python packages with --force-reinstall", but the default value is "--upgrade", which upgrades packages, not force-reinstalls them. This misrepresents the default behavior.

The past review comment suggested: "Extra arguments passed to pip when installing Python packages" (not "reinstalling with --force-reinstall").

📝 Proposed fix to align documentation with actual behavior
-        # Extra arguments passed to pip when reinstalling Python packages with --force-reinstall 
+        # Extra arguments passed to pip when installing Python packages.
         # By default, packages are upgraded on each playbook run.

As per coding guidelines, the past review comment suggested this exact wording to accurately describe the variable's purpose.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/user/role-variables.rst` at line 34, Update the documentation line
currently reading "# Extra arguments passed to pip when reinstalling Python
packages with --force-reinstall" to accurately reflect the variable's behavior:
describe it as extra arguments passed to pip when installing Python packages and
mention the default value "--upgrade" (e.g., "Extra arguments passed to pip when
installing Python packages (default: \"--upgrade\")") so the text matches the
actual default and intent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@docs/user/role-variables.rst`:
- Line 34: Update the documentation line currently reading "# Extra arguments
passed to pip when reinstalling Python packages with --force-reinstall" to
accurately reflect the variable's behavior: describe it as extra arguments
passed to pip when installing Python packages and mention the default value
"--upgrade" (e.g., "Extra arguments passed to pip when installing Python
packages (default: \"--upgrade\")") so the text matches the actual default and
intent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6522c501-2bcf-4e45-b89f-4af2592791b9

📥 Commits

Reviewing files that changed from the base of the PR and between 1d35ef6 and b5d9f31.

📒 Files selected for processing (2)
  • defaults/main.yml
  • docs/user/role-variables.rst
📜 Review details
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{yml,yaml,j2}

📄 CodeRabbit inference engine (AGENTS.md)

Avoid unnecessary blank lines inside Jinja, YAML, and shell blocks.

Files:

  • defaults/main.yml
**/*.{yml,yaml,j2,sh}

📄 CodeRabbit inference engine (AGENTS.md)

Write comments only when they explain why code is shaped a certain way. Put comments before the relevant block instead of scattering them inside it.

Files:

  • defaults/main.yml
**/*.{md,rst,txt}

📄 CodeRabbit inference engine (Custom checks)

**/*.{md,rst,txt}: Changes: If the change affects behavior that is already documented, the documentation must be updated to reflect the new behavior
Features: Documentation must mention the new feature; for heavily UI-related features, a new section or page is appropriate

Files:

  • docs/user/role-variables.rst
🔇 Additional comments (1)
defaults/main.yml (1)

239-240: LGTM!

@nemesifier
nemesifier merged commit 358c856 into openwisp:master Jun 3, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in 26.06 Release Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

[feature] Ensure all Python dependencies update on existing installs when playbook runs

3 participants