Skip to content

[ansible-openwisp2] Upgrade pip deps from requirements on rerun #575

Open
Piyushrathoree wants to merge 6 commits intoopenwisp:masterfrom
Piyushrathoree:feat/upgrade-pip-deps-572
Open

[ansible-openwisp2] Upgrade pip deps from requirements on rerun #575
Piyushrathoree wants to merge 6 commits intoopenwisp:masterfrom
Piyushrathoree:feat/upgrade-pip-deps-572

Conversation

@Piyushrathoree
Copy link
Copy Markdown

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
Author

@pandafy PTAL

Copy link
Copy Markdown
Member

@pandafy pandafy left a comment

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
Copy link
Copy Markdown
Author

Piyushrathoree commented Dec 10, 2025

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 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
Copy link
Copy Markdown

coderabbitai bot commented Mar 14, 2026

📝 Walkthrough

Walkthrough

This PR introduces a new Ansible variable openwisp2_pip_extra_args with a default value of "--upgrade" to enable automatic Python package upgrades when the playbook runs on existing installations. The variable is added to defaults, documented in the role variables guide, and integrated into five existing pip installation tasks (Python requirements, Django core headers, PostgreSQL driver, MySQL driver, and Celery email) to ensure dependencies are consistently updated across the infrastructure.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the correct [type] format with 'ansible-openwisp2' prefix and clearly describes the main change: upgrading pip dependencies on playbook rerun, which aligns with the linked issue #572.
Description check ✅ Passed The description covers the core requirement (updating pip.yml with --upgrade) and references the linked issue (#572), though test and documentation completion checkboxes are unchecked.
Linked Issues check ✅ Passed The PR successfully implements the feature requirement from #572 by adding a configurable variable openwisp2_pip_extra_args (defaulting to --upgrade) to pip tasks, enabling automatic dependency upgrades on playbook reruns.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing #572: adding the configurable pip extra arguments variable, updating pip tasks to use it, and documenting the new variable in role-variables.rst.
Bug Fixes ✅ Passed The custom check for 'Bug Fixes' is not applicable to this pull request. This PR implements a feature enhancement (issue #572 is explicitly labeled '[feature]') that adds a new configurable variable. The check only applies to bug fixes in core user-facing functionality, not feature requests.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants