Skip to content

fix: add verbosity-based no_log to facts modules#348

Merged
richm merged 1 commit into
linux-system-roles:mainfrom
spetrosi:parametrize-no-log
May 7, 2026
Merged

fix: add verbosity-based no_log to facts modules#348
richm merged 1 commit into
linux-system-roles:mainfrom
spetrosi:parametrize-no-log

Conversation

@spetrosi
Copy link
Copy Markdown
Contributor

@spetrosi spetrosi commented May 7, 2026

Feature: Add verbosity-based no_log to facts modules.

Reason: Facts modules like package_facts and service_facts produce verbose output that clutters logs during normal operation, making it difficult to review playbook execution.

Result:

  • package_facts and service_facts now use no_log: "{{ ansible_verbosity < 2 }}", hiding verbose output unless -vv or higher verbosity is specified
  • Users can still see full facts output when debugging by running with increased verbosity
  • No impact on normal operation, just cleaner logs

🤖 Generated with Claude Code

Summary by Sourcery

Control verbosity of facts gathering tasks to reduce log noise in normal runs while preserving debug visibility.

New Features:

  • Add verbosity-based no_log control to service_facts to hide output below -vv verbosity.
  • Add verbosity-based no_log control to package_facts to hide output below -vv verbosity.

- Add no_log: "{{ ansible_verbosity < 2 }}" to package_facts and service_facts

This hides verbose facts output unless ansible_verbosity >= 2,
reducing log clutter during normal operation while allowing
full output when debugging with -vv or higher.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 7, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds verbosity-dependent no_log behavior to Ansible facts tasks to reduce log noise while preserving debuggability.

Flow diagram for ansible_verbosity-driven no_log in facts modules

flowchart TD
  A[Start Ansible playbook] --> B[Run service_facts task]
  B --> C{ansible_verbosity < 2}
  C -- yes --> D[Set no_log to true for service_facts]
  C -- no --> E[Set no_log to false for service_facts]
  D --> F[Hide service_facts output in logs]
  E --> G[Show service_facts output in logs]
  F --> H[Run package_facts task]
  G --> H[Run package_facts task]
  H --> I{ansible_verbosity < 2}
  I -- yes --> J[Set no_log to true for package_facts]
  I -- no --> K[Set no_log to false for package_facts]
  J --> L[Hide package_facts output in logs]
  K --> M[Show package_facts output in logs]
  L --> N[Continue remaining tasks]
  M --> N[Continue remaining tasks]
  N[End playbook]
Loading

File-Level Changes

Change Details Files
Make service_facts and package_facts tasks respect ansible_verbosity for no_log to reduce log clutter.
  • Add no_log conditional expression based on ansible_verbosity for the service_facts task so output is hidden under normal verbosity
  • Add no_log conditional expression based on ansible_verbosity for the package_facts task so output is hidden under normal verbosity
tasks/main.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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • To make this more robust across different execution contexts, consider guarding ansible_verbosity with a default and explicit cast, e.g. no_log: "{{ (ansible_verbosity | default(0) | int) < 2 }}", so the task doesn’t break if ansible_verbosity is undefined or comes through as a string.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- To make this more robust across different execution contexts, consider guarding `ansible_verbosity` with a default and explicit cast, e.g. `no_log: "{{ (ansible_verbosity | default(0) | int) < 2 }}"`, so the task doesn’t break if `ansible_verbosity` is undefined or comes through as a string.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@richm richm merged commit 6542434 into linux-system-roles:main May 7, 2026
30 checks passed
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.

2 participants