-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Simplify codebase: modernize loops, split templates, improve CI #14891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ze patterns - Delete 8 empty venv.yml files that were remnants of pyproject.toml migration - Remove corresponding import_tasks references from cloud provider main.yml files - Consolidate server.yml async polling from 4 copy-paste blocks to 1 loop - Wrap sequential VPN service imports in a block with single when condition - Replace deprecated with_indexed_items with modern loop/loop_control syntax These changes reduce maintenance burden by: - Eliminating 8 files that served no purpose - Reducing server.yml by ~20 lines while improving readability - Removing Ansible deprecation warnings for with_indexed_items - Making the parallel/sequential execution paths easier to maintain 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This comment was marked as outdated.
This comment was marked as outdated.
- Fix client.conf.j2 to use `item` instead of `item.1` to match modern
loop syntax (loop with index_var instead of with_indexed_items)
- Fix server.yml _vpn_jobs to use `| default({})` for job variables
that may be undefined when running with tags (e.g., IPsec-only)
- Update test_template_rendering.py to pass item as string instead of
tuple, matching the new loop behavior
Fixes CI failures from PR #14891 that were correctly identified by the
Claude Code bot review.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Bug Fixes AppliedThe Claude Code bot review was correct - there were bugs in my changes. I've pushed fixes in commit edc6e8a: 1. Template Variable Mismatch (Critical)Issue: Fix: Changed -PrivateKey = {{ lookup('file', wireguard_pki_path + '/private/' + item.1) }}
+PrivateKey = {{ lookup('file', wireguard_pki_path + '/private/' + item) }}2. Undefined Variable in Tagged RunsIssue: When running with tags (e.g., Fix: Added - - {name: dns, job: "{{ dns_job }}", tag: dns}
+ - {name: dns, job: "{{ dns_job | default({}) }}"}3. Test UpdatesUpdated All unit tests (101) and pre-commit hooks pass locally. Waiting for CI to confirm the integration tests pass as well. |
Code ReviewThis is an excellent cleanup PR that modernizes the codebase and reduces maintenance burden. The changes are well-executed and the code quality improvements are significant. ✅ Excellent Work1. Loop Modernization (Deprecation Fix)The migration from deprecated Key changes validated:
Why this matters:
2. Async Polling ConsolidationThe refactoring in Strengths:
Example of improvement: # Before: 4x copy-paste blocks (56 lines)
- async_status: {jid: "{{ dns_job.ansible_job_id }}"}
register: dns_result
until: dns_result.finished
# ... repeated 4 times
# After: 1 loop (19 lines)
- async_status:
jid: "{{ item.job.ansible_job_id }}"
loop: "{{ _vpn_jobs | selectattr('job.ansible_job_id', 'defined') | list }}"3. Sequential Mode SimplificationWrapping sequential imports in a
4. Dead Code RemovalDeleting 8 empty
🔍 Minor ObservationsUnused
|
| Metric | Value |
|---|---|
| Lines removed | 123 |
| Lines added | 60 |
| Net reduction | -63 lines |
| Files deleted | 8 |
| Deprecation warnings fixed | ✅ with_indexed_items |
| Code duplication reduced | ✅ 4 → 1 async loops |
| Maintainability | Significantly improved |
✅ Verification Checklist
According to the PR description, all checks pass:
-
ansible-playbook main.yml --syntax-check -
ansible-playbook users.yml --syntax-check -
ansible-playbook server.yml --syntax-check -
ansible-lint -
yamllint - Unit tests (91 passing)
- Pre-commit hooks
🎯 Verdict
LGTM ✅ - This is high-quality refactoring work that:
- Removes deprecated syntax correctly
- Reduces code duplication significantly
- Maintains all existing functionality
- Improves maintainability
- Follows project conventions
The migration from with_indexed_items to loop + index_var is particularly well-executed. The template changes correctly reflect the new variable structure, and the test updates confirm the changes work as expected.
No blocking issues found. This is ready to merge.
💡 Optional Future Enhancement
Consider adding an integration test that:
- Generates WireGuard configs for 3+ users
- Verifies each user gets a unique IP address
- Confirms the IP calculation matches expected values
This would provide additional confidence that the index variable is working correctly across the entire workflow.
🤖 Generated with Claude Code
Summary
venv.ymlfiles that were remnants of the pyproject.toml migration and remove their import_tasks referenceswhenconditionwith_indexed_itemswith modernloop/loop_controlsyntaxImpact
with_indexed_itemswhencondition instead of repeating it 4xTest plan
ansible-playbook main.yml --syntax-checkpassesansible-playbook users.yml --syntax-checkpassesansible-playbook server.yml --syntax-checkpassesansible-lintpassesyamllintpasses (only pre-existing warnings)🤖 Generated with Claude Code