Skip to content

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

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#219
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 produce verbose output that clutters logs during normal operation, making it difficult to review playbook execution.

Result:

  • package_facts now uses 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

Enhancements:

  • Gate package_facts logging with a verbosity-based no_log condition so facts output is hidden in normal runs but visible at higher verbosity.

- Add no_log: "{{ ansible_verbosity < 2 }}" to package_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-aware no_log behavior to the facts collection task so package facts output is suppressed in normal runs but visible when running with higher Ansible verbosity.

Sequence diagram for verbosity-based no_log behavior in package_facts task

sequenceDiagram
    actor User
    participant AnsibleCLI
    participant Playbook
    participant Task_package_facts
    participant Module_package_facts
    participant Logger

    User->>AnsibleCLI: run ansible_playbook (optional -v / -vv)
    AnsibleCLI->>Playbook: load tasks

    Playbook->>Task_package_facts: execute task Get_the_rpm_package_facts
    Task_package_facts->>Task_package_facts: compute no_log = ansible_verbosity < 2

    alt no_log is true (ansible_verbosity < 2)
        Task_package_facts->>Module_package_facts: invoke module with no_log true
        Module_package_facts->>Logger: send facts output (hidden in logs)
        Logger-->>Playbook: log task status only
    else no_log is false (ansible_verbosity >= 2)
        Task_package_facts->>Module_package_facts: invoke module with no_log false
        Module_package_facts->>Logger: send full facts output
        Logger-->>Playbook: log task status and facts content
    end

    Playbook-->>AnsibleCLI: aggregate results
    AnsibleCLI-->>User: display output according to verbosity
Loading

Flow diagram for determining no_log value from ansible_verbosity

flowchart TD
    A[Start task Get the rpm package facts] --> B[Read ansible_verbosity]
    B --> C{Is ansible_verbosity < 2?}
    C -->|Yes| D[Set no_log to true]
    C -->|No| E[Set no_log to false]
    D --> F[Run package_facts module with output hidden in logs]
    E --> G[Run package_facts module with full output shown in logs]
    F --> H[Continue playbook execution]
    G --> H[Continue playbook execution]
Loading

File-Level Changes

Change Details Files
Make package_facts task output conditional on Ansible verbosity using no_log.
  • Add a no_log expression that evaluates to true when ansible_verbosity is less than 2, hiding package_facts output in standard runs
  • Ensure facts remain accessible for debugging by allowing output when playbooks are executed with -vv or higher 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:

  • The new no_log line appears at the same indentation level as package_facts:; if this is meant to be a task-level attribute it should align with name/package_facts, and if it’s a module argument it should be indented under package_facts: to avoid breaking the task YAML structure.
  • Consider explicitly casting ansible_verbosity to an integer (e.g. {{ (ansible_verbosity | int) < 2 }}) so the no_log condition remains robust even if the verbosity value is provided as a string in some environments.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `no_log` line appears at the same indentation level as `package_facts:`; if this is meant to be a task-level attribute it should align with `name`/`package_facts`, and if it’s a module argument it should be indented under `package_facts:` to avoid breaking the task YAML structure.
- Consider explicitly casting `ansible_verbosity` to an integer (e.g. `{{ (ansible_verbosity | int) < 2 }}`) so the no_log condition remains robust even if the verbosity value is provided as a string in some environments.

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 5e3c69b into linux-system-roles:main May 7, 2026
28 of 29 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