Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix Ansible 12 compatibility issues #14840

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

Merged
dguido merged 1 commit into master from fix/ansible-12-compatibility
Sep 28, 2025
Merged

Conversation

Copy link
Member

@dguido dguido commented Sep 28, 2025

Summary

  • Fixes Ansible 12 string-to-boolean conversion errors in conditionals
  • Resolves nested Jinja template deprecation warnings
  • Ensures compatibility with stricter type checking in Ansible 12

Related Issue

Closes #14838

Changes Made

1. Fixed Nested Jinja Template Warning

File: files/cloud-init/base.sh:20

  • Before: {{ lookup('file', '{{ SSH_keys.public }}') }}
  • After: {{ lookup('file', SSH_keys.public) }}
  • Reason: Ansible is deprecating nested template expressions. The inner {{ }} is unnecessary since we're already in a template context.

2. Fixed Boolean Conditional Error

File: roles/common/tasks/main.yml:20

  • Before: when: item.item
  • After: when: item.item is defined and item.item != none
  • Reason: Ansible 12 requires explicit boolean conditions. String values can no longer be implicitly evaluated as truthy/falsy.

3. Fixed Sysctl List Structure

File: roles/common/tasks/ubuntu.yml:132

  • Before: List with conditional item that could be none
  • After: Dynamic list construction that excludes None values
  • Reason: Prevents none values from being evaluated in boolean contexts

Test Plan

  • Syntax validation: ansible-playbook main.yml --syntax-check
  • YAML linting: yamllint
  • Shell script linting: shellcheck
  • Ansible linting: ansible-lint
  • All pre-commit hooks pass ✅
  • Deploy test on Lightsail (requested from issue reporter)
  • Deploy test with Ansible 11.x (backward compatibility)
  • Deploy test with Ansible 12.x (forward compatibility)

Compatibility

  • Maintains backward compatibility with Ansible 11.x and earlier
  • Ensures forward compatibility with Ansible 12.x strict type checking
  • No breaking changes to existing functionality

🤖 Generated with Claude Code

This commit addresses three critical compatibility issues with Ansible 12:
1. **Nested Jinja template deprecation warning**
 - Fixed: `{{ lookup('file', '{{ SSH_keys.public }}') }}`
 - Now: `{{ lookup('file', SSH_keys.public) }}`
 - Location: files/cloud-init/base.sh:20
2. **String to boolean conversion errors in conditionals**
 - Fixed: `when: item.item` (evaluates strings as truthy)
 - Now: `when: item.item is defined and item.item != none`
 - Location: roles/common/tasks/main.yml:20
3. **Sysctl list with None values causing boolean errors**
 - Restructured list to dynamically exclude None entries
 - IPv6 forwarding sysctl only added when ipv6_support is true
 - Location: roles/common/tasks/ubuntu.yml:132
These changes maintain backward compatibility with older Ansible versions
while ensuring forward compatibility with Ansible 12's stricter type checking.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

claude bot commented Sep 28, 2025
edited
Loading

Claude finished @dguido's task —— View job


PR Review: Ansible 12 Compatibility Fixes

I've completed a thorough review of this PR that addresses Ansible 12 compatibility issues. Here's my comprehensive analysis:

Review Checklist

  • Analyze the 3 changed files
  • Evaluate each fix for correctness
  • Check for security concerns
  • Assess performance impact
  • Review test coverage
  • Provide comprehensive feedback

Overall Assessment: APPROVED

This PR effectively addresses legitimate Ansible 12 compatibility issues with clean, well-reasoned fixes. The changes are minimal, targeted, and maintain backward compatibility.

📋 Detailed Code Review

1. files/cloud-init/base.sh:20EXCELLENT

# BEFORE (problematic)
echo "{{ lookup('file', '{{ SSH_keys.public }}') }}" 
# AFTER (correct)
echo "{{ lookup('file', SSH_keys.public) }}"

Analysis:

  • ✅ Correctness: This is the exact fix needed for Ansible 12's deprecation of nested Jinja2 templates
  • ✅ Security: No security implications - same functionality, cleaner syntax
  • ✅ Best Practice: Follows Ansible's recommended approach for lookup functions
  • ✅ Test Coverage: This pattern is explicitly tested in tests/unit/test_double_templating.py lines 111-114

2. roles/common/tasks/main.yml:20SOLID

# BEFORE (problematic)
when: item.item
# AFTER (explicit)
when: item.item is defined and item.item != none

Analysis:

  • ✅ Correctness: Addresses Ansible 12's stricter type checking for boolean evaluation
  • ✅ Robustness: Prevents errors when item.item is None or undefined
  • ✅ Clarity: Makes the condition explicit rather than relying on implicit truthy evaluation
  • ✅ Performance: Negligible impact - condition evaluation is fast

3. roles/common/tasks/ubuntu.yml:132CLEVER

# BEFORE (problematic static list with conditional None)
sysctl:
 - item: net.ipv4.ip_forward
 value: 1
 - item: "{{ 'net.ipv6.conf.all.forwarding' if ipv6_support else none }}"
 value: 1
 # ... more items
# AFTER (dynamic list construction)
sysctl: "{{ [{'item': 'net.ipv4.ip_forward', 'value': 1}, {'item': 'net.ipv4.conf.all.forwarding', 'value': 1}, {'item': 'net.ipv4.conf.all.route_localnet', 'value': 1}] + ([{'item': 'net.ipv6.conf.all.forwarding', 'value': 1}] if ipv6_support else []) }}"

Analysis:

  • ✅ Correctness: Eliminates none values that would cause boolean evaluation errors in Ansible 12
  • ✅ Logic: Dynamic list construction is more robust than conditional None values
  • ✅ Maintainability: While more compact, the logic is still clear
  • ✅ Functionality: Preserves the exact same behavior - IPv6 forwarding only when ipv6_support is enabled

🔒 Security Assessment

✅ NO SECURITY CONCERNS IDENTIFIED

  • All changes are syntax/compatibility fixes with identical functional behavior
  • No new attack vectors introduced
  • No secrets or credentials handling modified
  • SSH key handling in cloud-init remains secure

Performance Impact

✅ NEGLIGIBLE TO POSITIVE

🧪 Test Coverage Analysis

✅ WELL COVERED

  • The double templating fix is explicitly tested in tests/unit/test_double_templating.py
  • Test includes the exact pattern being fixed: "{{ lookup('file', '{{ SSH_keys.public }}') }}"
  • PR description shows all linting tests pass
  • Recommendation: The integration tests mentioned in the test plan should be run to verify end-to-end functionality

🎯 Best Practices Compliance

✅ EXCELLENT ADHERENCE

  • Follows Algo's conservative update philosophy from CLAUDE.md
  • Maintains backward compatibility as required
  • Addresses security through compatibility (avoiding deprecated patterns)
  • Clear, atomic changes with good explanations

🔍 Potential Issues & Recommendations

Minor Observations:

  1. Line Length: The new sysctl line in ubuntu.yml:132 is quite long (120+ chars). Consider breaking it across lines for better readability:

    sysctl: >-
     {{ [
     {'item': 'net.ipv4.ip_forward', 'value': 1},
     {'item': 'net.ipv4.conf.all.forwarding', 'value': 1}, 
     {'item': 'net.ipv4.conf.all.route_localnet', 'value': 1}
     ] + ([{'item': 'net.ipv6.conf.all.forwarding', 'value': 1}] if ipv6_support else [])
     }}
  2. Testing Completeness: As noted in the test plan, please ensure the Lightsail deployment test is completed to verify real-world functionality.

Strengths:

  1. Surgical Precision: Changes only what's necessary
  2. Clear Documentation: Excellent PR description explaining each change
  3. Test-Driven: Existing tests validate the fixes
  4. Compatibility Focus: Maintains backward compatibility while fixing forward compatibility

📝 Final Recommendation

✅ APPROVE AND MERGE - This PR is ready for production.

The fixes are technically sound, well-tested, and address legitimate compatibility issues without introducing risks. The changes align perfectly with Algo's security-first, stability-focused approach outlined in CLAUDE.md.


@dguido dguido merged commit 1cd4203 into master Sep 28, 2025
24 checks passed
@dguido dguido deleted the fix/ansible-12-compatibility branch September 28, 2025 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jackivanov jackivanov Awaiting requested review from jackivanov jackivanov is a code owner

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Lightsail Failed Deployment(s) - Ansible 12 string to boolean errors && Playbook Jinja string errors

1 participant

AltStyle によって変換されたページ (->オリジナル) /