8000 fix: pass provisioner verbosity options to ansible by jeffcpullen · Pull Request #4709 · ansible/molecule · GitHub
[go: up one dir, main page]

Skip to content

fix: pass provisioner verbosity options to ansible - #4709

Merged
shvenkat-rh merged 4 commits into
ansible:mainfrom
jeffcpullen:fix/provisioner-options-verbosity
Oct 28, 2026
Merged

shvenkat-rh merged 4 commits into
ansible:mainfrom
jeffcpullen:fix/provisioner-options-verbosity

Conversation

@jeffcpullen
@jeffcpullen jeffcpullen commented Sep 23, 2026 •
Copy link
Copy Markdown
Contributor

fix: pass provisioner verbosity options to ansible

Fixes #3159.

Problem

The Ansible provisioner's verbosity option is documented as a way to raise Ansible verbosity, but it is silently dropped. The flag never reaches the ansible-playbook (or ansible-navigator) command line, so the run stays at verbosity 0. The same drop affects molecule --debug, which raises verbosity the same way internally, so --debug ran Ansible at verbosity 0 as well.

The scenario below sets the documented option and runs converge on it. On a clean checkout the run shows none of the markers Ansible prints only at verbosity 1 and above, such as the interpreter banner and the per-task path lines.

# molecule/default/molecule.yml
driver:
  name: default
  options:
    managed: false
platforms:
  - name: instance
provisioner:
  name: ansible
  options:
    vvv: true
  inventory:
    host_vars:
      instance:
        ansible_connection: local

Molecule converge - missing expected 'task path:' debug output

# molecule converge
<snip>
TASK [Say hello] ***************************************************************
ok: [instance] => {
    "msg": "hello-from-converge"
}
<snip>

Molecule converge with --debug - missing expected 'task path:' debug output

# molecule --debug converge -s scenario_debug
<snip>
TASK [Say hello] ***************************************************************
ok: [instance] => {
    "msg": "hello-from-converge"
}
<snip>

No verbosity banner, no task path:. Neither -vvv nor --debug was applied.

Root cause

In src/molecule/provisioner/ansible_playbook.py, bake() computes the flag correctly (verbose_flag = util.verbose_flag(options) yields ["-vvv"] and strips the v* keys from options). But _build_command() then emits it through util.bool2args(verbose_flag), and util.bool2args is a stub that unconditionally returns [] regardless of its argument. The finished ["-vvv"] is computed and thrown away.

bool2args was born a no-op in the 2020 refactor that moved command building off the sh library (#2917). The same change handled the two sibling call sites (the ansible-galaxy dep 8000 endency step and the testinfra verifier) correctly, spreading *verbose_flag inline, which is why only provisioner.options verbosity is affected. A later navigator-executor rewrite (#4457) copied the broken line into the ansible-navigator branch, so both backends now drop it. bool2args has no other callers. The option worked from 2017 until #2917 and is still the documented way to set per-scenario verbosity, so this restores it rather than removing the docs.

The gap stayed quiet for ~5 years because the tests assert the computed value (verbose_flag() returns ["-vvv"]) and the config object (options contains vvv: True), but never the built command. The galaxy path already has a bake-level test asserting -v reaches the command. The provisioner lacked the equivalent.

Changes

  • Spread *verbose_flag directly in both backend branches of _build_command() (ansible-playbook and ansible-navigator), matching the galaxy dependency and testinfra verifier paths that already work.
  • Remove util.bool2args, whose only two callers were these lines.
  • Add bake-level tests asserting the verbosity flag reaches the built command, parametrized over v / vv / vvv for both backends and covering the --debug path.

With the fix, the same scenario raises verbosity: the ansible-playbook [core ...] banner and task path: lines now appear.

# molecule converge
<snip>
TASK [Say hello] ***************************************************************
task path: molecule/default/converge.yml:5
ok: [instance] => {
    "msg": "hello-from-converge"
}
<snip>

molecule --debug raises verbosity through the same internal path, and was dropped the same way. Run against the same setup, minus any provisioner.options, so the --debug flag is the only variable. Before the fix it still runs at verbosity 0. With the fix, the banner and per-task path appear.

# molecule --debug converge -s scenario_debug
<snip>
TASK [Say hello] ***************************************************************
task path: molecule/scenario_debug/converge.yml:5
ok: [instance] => {
    "msg": "hello-from-converge"
}
<snip>

Environment for all runs: ansible-core 2.21.4, Python 3.13. Before is a clean upstream/main. After is that same base plus this commit.

The transcripts above exercise the ansible-playbook backend. The ansible-navigator backend carries the identical fix and is covered by the parametrized bake test that asserts the flag reaches its command line.

Risk / Impact

None known

Test plan

  • tox -e lint green
  • tox -e pkg green
  • tox -e py full suite green, same skips as main (918 passed / 7 skipped, vs 911 / 7 on main)
  • New bake tests red on main, green on the branch, one per backend (7 fail on main: v/vv/vvv for each backend plus the --debug test)
  • Coverage flat vs main (90% on both)
  • Docs unchanged, the documented provisioner.options.vvv example now behaves as documented

Related

  • The two documented paths that already raise verbosity today: molecule -v/-vv/-vvv converge, and provisioner.env: {ANSIBLE_VERBOSITY: 3}.

Summary by CodeRabbit

  • Bug Fixes
    • Verbosity settings are now applied correctly to commands run by Ansible Playbook and Ansible Navigator. Selecting v, vv, or vvv produces the corresponding verbosity level, and enabling debug mode applies maximum verbosity. Command output now reflects the selected level in both execution modes.

@coderabbitai
coderabbitai Bot commented Sep 23, 2026 •
Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 31465d2f-e6a0-4e60-a1f3-cce54014fd58
📥 Commits

Reviewing files that changed from the base of the PR and between e312dea and 9e4702f.

📒 Files selected for processing (1)
  • src/molecule/provisioner/ansible_playbook.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

The Ansible provisioner now adds configured verbosity flags to generated ansible-playbook and ansible-navigator commands. Unit tests cover v, vv, vvv, and debug mode.

Changes: Ansible verbosity

Layer / File(s) Summary
Build and test verbosity commands
src/molecule/provisioner/ansible_playbook.py, src/molecule/util.py, tests/unit/provisioner/test_ansible_playbook.py
Both command builders append verbosity flags directly, and the unused bool2args helper is removed. Tests cover v, vv, and vvv for both backends and verify that debug mode adds -vvv. Other test changes add annotations, docstrings, and a provisioner configuration assertion.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: cidrblock

Merge Risk: Minimal · previous review 9e470

Configured Ansible verbosity now reaches both backends, including debug mode. The inspected command construction and tests reveal no actionable risk that should delay merging.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: passing provisioner verbosity options to Ansible.
Linked Issues check ✅ Passed Issue #3159 requires v, vv, and vvv provisioner options to reach Ansible. AnsiblePlaybook._build_command now adds the computed verbose_flag to both ansible-playbook and ansible-navigator…
Out of Scope Changes check ✅ Passed The command changes and tests address issue #3159. Removing util.bool2args supports the fix because the changed call sites no longer use that no-op helper. Test annotations and documentation strings…
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

`provisioner.options.vvv` (and `vv`/`v`) is documented to raise Ansible
verbosity but is silently dropped: the command builder routed the extracted
verbose flag through `util.bool2args()`, a no-op stub that always returns an
empty list, so `-vvv` never reached the ansible-playbook or ansible-navigator
command line. The same drop affects `molecule --debug`, which sets `vvv`
internally, so `--debug` also ran Ansible at verbosity 0.

Spread `verbose_flag` directly in both backend branches of `_build_command()`,
matching how the ansible-galaxy dependency and testinfra verifier already emit
it, and remove the unused `bool2args` helper (its only two callers were these
lines).

Add bake-level tests asserting the verbosity flag reaches the built command,
parametrized over `v`/`vv`/`vvv` for both backends and covering the `--debug`
path.

Fixes ansible#3159

Assisted-by: Claude (Anthropic)
Signed-off-by: Jeff Pullen <9343691+jeffcpullen@users.noreply.github.com>
@jeffcpullen
jeffcpullen force-pushed the fix/provisioner-options-verbosity branch from f89221e to 186c142 Compare September 24, 2026 19:40
@Hrithik-Gavankar
Copy link
Copy Markdown
Contributor

Hi @jeffcpullen,
Thanks for the PR!

LGTM. Root cause analysis is accurate: bool2args has been a no-op since #2917; galaxy/testinfra already spread verbose_flag. Restoring *verbose_flag for both executor backends fixes documented provisioner.options verbosity and molecule --debug for Ansible runs. New bake tests close the hole between verbose_flag() unit tests and the actual argv.

Please get CI green first (the current tox / lint failure and any noise from the merge commit / uv.lock); once that’s resolved I’m happy to approve. A clean rebase onto main may be the simplest way to drop unrelated lockfile churn.

@jeffcpullen
Copy link
Copy Markdown
Contributor Author

Thanks @Hrithik-Gavankar. The tox / lint failure is on main too (run). The latest cspell knows the word worktree, so the hook prunes it from .config/dictionary.txt and the check fails on the modified file. #4710 carries that dictionary change and is green. Once it merges I'll rebase onto main, which also drops the merge commit.

@jeffcpullen
Copy link
Copy Markdown
Contributor Author

Please get CI green first (the current tox / lint failure and any noise from the merge commit / uv.lock); once that’s resolved I’m happy to approve. A clean rebase onto main may be the simplest way to drop unrelated lockfile churn.

@Hrithik-Gavankar we are back to green now that #4710 is merged

@shvenkat-rh
shvenkat-rh merged commit 598bdbb into ansible:main Oct 28, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Can't specify Ansible verbosity as a molecule option

4 participants

0