Skip to content

Conversation

@martinpitt
Copy link
Contributor

@martinpitt martinpitt commented Jun 15, 2025

Cause: Ansible 2.19 changed behaviour: Any value which is "none" gets
rendered as literal "None" string instead of "not rendered"/"empty
string.

Consequence: The generated config file was completely broken with
Ansible 2.19.

Fix: Add explicit is not none guards. Also refactor the template with
an ssh_options list to be less repetitive.

Thanks to Claude-Sonnet 3.7 LLVM which heavily assisted with this
change.


This should fix Ansible 2.19 faliures. My train ride ends now, so I couldn't test this very thoroughly yet. Let's ask CI! Hence draft still.

Summary by Sourcery

Rewrite the SSH configuration template to guard against undefined or none values for Ansible 2.19 compatibility, simplify the rendering logic by consolidating option handling into a list-driven approach, and update tests to reflect new SSH config file paths.

Bug Fixes:

  • Prevent literal “None” values in generated SSH config by adding explicit is not none checks for Ansible 2.19 compatibility.

Enhancements:

  • Refactor Jinja2 macros to iterate over a centralized ssh_options list and streamline render_option, body_option, match_block, and host_block logic.

Tests:

  • Update default test playbooks to use /etc/ssh/ssh_config.d/00-ansible.conf and /etc/ssh/ssh_config file paths.

The other tests have that right.
Cause: Ansible 2.19 changed behaviour: Any value which is "none" gets
rendered as literal "None" string instead of "not rendered"/"empty
string.

Consequence: The generated config file was completely broken with
Ansible 2.19.

Fix: Add explicit `is not none` guards. Also refactor the template with
an `ssh_options` list to be less repetitive.

Thanks to Claude-Sonnet 3.7 LLVM which heavily assisted with this
change.
@sourcery-ai
Copy link

sourcery-ai bot commented Jun 15, 2025

Reviewer's Guide

The template macros in ssh_config.j2 have been rewritten to explicitly guard against None values, eliminate hardcoded option lists by iterating over key/value pairs, and consolidate repeated body_option calls into a single loop driven by a ssh_options array; tests_default.yml was updated to reflect the new SSH config file paths.

File-Level Changes

Change Details Files
Add explicit None checks in template macros
  • Guard all value tests with is not none
  • Change initial undefined to none in body_option
  • Wrap render_option calls to skip None values
templates/ssh_config.j2
Replace hardcoded option lists with dynamic loops
  • Remove explicit render_option calls in match_block and host_block
  • Introduce for-loops over dict items filtering out Condition
  • Filter out undefined or None values during iteration
templates/ssh_config.j2
Consolidate body_option invocations using ssh_options array
  • Define ssh_options list of all keys
  • Replace dozens of body_option calls with a single for-loop
  • Resolve var precedence within the loop for vars, ssh, and defaults
templates/ssh_config.j2
Update test backup paths
  • Prefix backup file paths with /etc/ssh/ in tests_default.yml
tests/tests_default.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@martinpitt
Copy link
Contributor Author

Superseded by #191, thanks @richm !

@martinpitt martinpitt deleted the a219 branch June 18, 2025 04:31
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.

1 participant