Skip to content

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

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

fix: add verbosity-based no_log to facts modules#276
richm merged 1 commit intolinux-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

New Features:

  • Conditionally hide package_facts output using no_log based on Ansible verbosity level.

- 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>
@spetrosi spetrosi requested review from ptoscano and richm as code owners May 7, 2026 13:06
@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 package_facts task to reduce log noise while preserving debuggability.

Sequence diagram for verbosity-based no_log behavior in package_facts task

sequenceDiagram
    actor AnsibleUser
    participant AnsibleCLI
    participant Playbook
    participant Task_package_facts
    participant Logger

    AnsibleUser->>AnsibleCLI: run ansible_playbook with verbosity
    AnsibleCLI->>Playbook: execute tasks
    Playbook->>Task_package_facts: run package_facts
    Task_package_facts->>Task_package_facts: evaluate ansible_verbosity < 2
    alt verbosity_less_than_2
        Task_package_facts->>Logger: suppress facts output (no_log true)
    else verbosity_2_or_more
        Task_package_facts->>Logger: log full package_facts output (no_log false)
    end
    Logger-->>AnsibleCLI: aggregated logs
    AnsibleCLI-->>AnsibleUser: display logs according to verbosity
Loading

Flow diagram for no_log decision in package_facts task

flowchart TD
    Start[Start package_facts task]
    V[Read ansible_verbosity]
    C{ansible_verbosity < 2}
    NLTrue[Set no_log to true
hide package_facts output]
    NLFalse[Set no_log to false
show package_facts output]
    End[Continue playbook execution]

    Start --> V --> C
    C -->|yes| NLTrue --> End
    C -->|no| NLFalse --> End
Loading

File-Level Changes

Change Details Files
Make package_facts output conditional on Ansible verbosity using no_log.
  • Add a no_log expression that hides package_facts output when ansible_verbosity is below 2
  • Ensure facts collection still runs unchanged, only affecting logging behavior
tasks/set_vars.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 no_log key should be indented at the task level (alongside name, package_facts, and when) rather than under package_facts, since no_log is a task attribute, not a module parameter; otherwise Ansible will treat it as an unexpected argument to package_facts.
  • To make the verbosity check more robust, consider explicitly casting ansible_verbosity to an integer (no_log: "{{ (ansible_verbosity | int) < 2 }}") so the condition behaves predictably even if ansible_verbosity is passed as a string.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `no_log` key should be indented at the task level (alongside `name`, `package_facts`, and `when`) rather than under `package_facts`, since `no_log` is a task attribute, not a module parameter; otherwise Ansible will treat it as an unexpected argument to `package_facts`.
- To make the verbosity check more robust, consider explicitly casting `ansible_verbosity` to an integer (`no_log: "{{ (ansible_verbosity | int) < 2 }}"`) so the condition behaves predictably even if `ansible_verbosity` is passed 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 b719037 into linux-system-roles:main May 7, 2026
28 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